public static String EncryptAES(SecretKeySpec spec, String input) throws Exception {
byte [] kataSandi = input.getBytes();
String iv = "fc19366826cd8f30";
byte[] ivBytes = iv.getBytes();
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding","BC");
cipher.init(Cipher.ENCRYPT_MODE, spec, ivSpec);
byte[] cipherText = cipher.doFinal(kataSandi);
String sandi = new String(Base64.encode(cipherText));
return sandi;
}
public static String DecryptAES(SecretKeySpec spec, String input) throws Exception {
byte[] cipherText = Base64.decode(input);
String iv = "fc19366826cd8f30";
byte[] ivBytes = iv.getBytes();
IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding","BC");
cipher.init(Cipher.DECRYPT_MODE, spec, ivSpec);
byte[] plainText = cipher.doFinal(cipherText);
String plain = new String(plainText);
return plain;
}
Minggu, 17 Juli 2011
Source code Java Enkripsi-Dekripsi AES 256 Base64 (using BoucyCastle)
Langganan:
Posting Komentar (Atom)
1 komentar:
mas boleh mintak projex e gak, tolong kirim di gmail ku,
infos7001@gmail.com
Posting Komentar
Terima kasih atas komentar Anda :)