Tag: Rijndael

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"); …

Cross-Platform, PHP

Simple AES Encryption with PHP

Today we will see how we can use mcrypt_encrypt PHP function to encrypt a plain text using AES 128! 1 2 3 4 5 6 7 8 function encrypt($plaintext, $key) { $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB); return base64_encode($crypt); }function encrypt($plaintext, $key) { $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB); return base64_encode($crypt); } Usage: $cipher_text = …