Home > Back-end >  Consult in Java Cipher. GetInstance (String) error problem
Consult in Java Cipher. GetInstance (String) error problem

Time:09-18

I am writing the Cipher decryption algorithm used when statements. GetInstance (DES/CBC/PKCS5Padding "), but the compiler errors as follows
Package Decode;
Import the Java. Security. *;
The import javax.mail. Crypto. *;
The import javax.mail. Crypto. Spec. SecretKeySpec;
Public class mail_Phone_PwdDe {
Public static void main (String args []) throws
NoSuchAlgorithmException, NoSuchPaddingException {
Excuse me how should solve?

CodePudding user response:

 
/* *

* encrypted data* @ param content need to encrypt the contents of the
* @ param password encryption password
* @ return
*/
Public static byte [] encryptForAES (byte [] content, String password) {
If (the content==null | | content. length==0 | | password==null) return null;
Try {//don't need so complicated key
//KeyGenerator kgen=KeyGenerator. GetInstance (AES, "");
//kgen. Init (128, new SecureRandom (password. GetBytes (" utf-8 ")));
//SecretKey SecretKey.=kgen generateKey ();
//byte [] enCodeFormat=secretKey. GetEncoded ();
Byte [] enCodeFormat=getBytesForUTF8 (password);
SecretKeySpec key=new SecretKeySpec(enCodeFormat, "AES");
Cipher Cipher=Cipher. GetInstance (" AES/the ECB/PKCS5Padding ");//create a password, and the ECB mode, AES/PKCS5Padding filling way the ECB/PKCS5Padding
Cipher. The init (cipher ENCRYPT_MODE, key);//initialized to encrypt mode
Result=cipher byte []. DoFinal (content);
return result;//encryption
} the catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} the catch (NoSuchPaddingException e) {
e.printStackTrace();
} the catch (InvalidKeyException e) {
e.printStackTrace();
} the catch (IllegalBlockSizeException e) {
e.printStackTrace();
} the catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}

CodePudding user response:

Because you don't have a source out, try the above method, should be able to solve your problem, he this encryption method is correct
  • Related