简单对一个string进行AES加密
import javax.crypto.*;
import java.security.*;
try{
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecretKey deskey = keyGen.generateKey();
Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, deskey);
byte[] enc = c.doFinal(new String("abcdegfsfsdfsaffsdf").getBytes("UTF8"));
String str = String.valueOf(enc);
}
catch (NoSuchAlgorithmException e){
e.printStackTrace();
}
catch (InvalidKeyException e) {
e.printStackTrace();
}
catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
catch (BadPaddingException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
No comments:
Post a Comment