Tag: base64

C, Programming

RC4 and Base64 using CryptoAPI and C

In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher. While remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure. It is especially vulnerable when the beginning of the output keystream is not discarded, or …

C, Programming

Base64 with CryptoAPI and C

CryptBinaryToString The CryptBinaryToString function converts an array of bytes into a formatted string. – MSDN CryptStringToBinary The CryptStringToBinary function converts a formatted string into an array of bytes. – MSDN Base64 Encoding bool Base64EncodeA(char **dest, unsigned long *dlen, const unsigned char *src, unsigned long slen) { if (src == NULL) return false;   if (!CryptBinaryToStringA(src, …

C

Base64 with OpenSSL in C

Assuming that you have already built OpenSSL for Windows. Check this guide for details. Link your project with this library from OpenSSL, libeay32.lib. Definitions and Includes: #include <stdlib.h> #include <stdio.h> #include <windows.h> #include <stdbool.h>   #include <openssl/bio.h> #include <openssl/evp.h> #include <openssl/buffer.h>   bool Base64Encode(char **dest, const char *src, unsigned int slen); bool Base64Decode(char **dest, const …

C#

Load Picture into PictureBox from base64 String

  String ImageText = "blahblahblahblahblah=="; Byte[] bitmapData = new Byte[ImageText.Length]; bitmapData = Convert.FromBase64String(FixBase64ForImage(ImageText)); System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData); Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap)); pictureBox1.Image = bitImage;   private String FixBase64ForImage(String Image) { try { System.Text.StringBuilder st = new System.Text.StringBuilder(Image, Image.Length); st.Replace("rn", String.Empty); st.Replace(" ", String.Empty); return st.ToString(); } catch (Exception ex) { return ""; } …

Java

Encrypt string using AES 128 – Java

You need Apache Commons Codec. package encryption.aes;   import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64;   public class aes128 {   public static void main(String args[]) { String plain = "testtesttesttesttesttesttesttest"; String ivkey = "abcdefgh12345678";   byte[] ivraw = ivkey.getBytes(); SecretKeySpec skeySpec = new SecretKeySpec(ivraw, "AES"); …

C#

Base64 Encoding and Decoding in C#

Encoding string to Base64 format: public String Encode2Base64(String text) { try { return Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(text)); } catch (Exception) { return null; } }public String Encode2Base64(String text) { try { return Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(text)); } catch (Exception) { return null; } } Decoding string from Base64 format: public String DecodefromBase64(String text) { try { return Encoding.ASCII.GetString(Convert.FromBase64String(text)); } catch (Exception) …

PHP

Convert image to string with PHP

To convert an image file to a string we have to encode image file contents with base64 algorithm. 1 2 3 $image = "it.jpg"; $imgstr = base64_encode(fread(fopen($image, "r"), filesize($image))); <img src="data:image/jpg;base64,$imgstr"/>$image = "it.jpg"; $imgstr = base64_encode(fread(fopen($image, "r"), filesize($image))); <img src="data:image/jpg;base64,$imgstr"/>