Tag: aes

PHP

OpenSSL AES 256 CBC encryption in PHP

define(’AES_METHOD’, ‘AES-256-CBC’);   class AES256 { public function Encrypt($password, $plainText) { if(empty($password) || empty($plainText)) { return FALSE; }   //generate a random salt $Salt = openssl_random_pseudo_bytes(8); if($Salt === FALSE){ return FALSE; }   //generate a random initialization vector $IV = openssl_random_pseudo_bytes( openssl_cipher_iv_length( AES_METHOD)); if($IV === FALSE){ return FALSE; }   //generate aes key $pwd = …

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 = …