java, data decryption
There is a string encryption/decryption class.
Encryption function:
public static String DESEncrypt(String datasource, String password) {
String result = datasource;
if (datasource != null) {
try {
if (!datasource.isEmpty()) {
SecretKey securekey = SecretKeyFactory.getInstance("DES").generateSecret(new DESKeySpec(password.substring(0, 8).getBytes(Hex.DEFAULT_CHARSET_NAME)));
AlgorithmParameterSpec iv = new IvParameterSpec(ivkey);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(1, securekey, iv);
result = Base64.encodeToString(cipher.doFinal(datasource.getBytes(Hex.DEFAULT_CHARSET_NAME)), 0);
}
} catch (Throwable e) {
Log.i("@error", e.getMessage());
}
}
return result;
}
Decryption function:
public static String DESDecrypt(String src, String password) {
String result = src;
if (src == null) {
return result;
}
if (src.isEmpty()) {
return result;
}
byte[] item = password.substring(0, 8).getBytes();
try {
DESKeySpec item2 = new DESKeySpec(item);
SecretKey securekey = SecretKeyFactory.getInstance("DES").generateSecret(item2);
} catch (InvalidKeyException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
return password.substring(0, 8);
/*AlgorithmParameterSpec iv = new IvParameterSpec(ivkey);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(2, securekey, iv);
return new String(cipher.doFinal(Base64.getDecoder().decode(src)));*/
}
I am interested in the decryption function, when I run it, I see an error on the line
SecretKey securekey = SecretKeyFactory.getInstance("DES").generateSecret(item2);
Gentlemen experts, tell me, what am I doing wrong?
I am an expert in php,mysql.
0
Author: Alexander Chernin, 2017-06-05
1 answers
I would venture to assume that you need to install an extension to work with JCE cryptography download documentation
0
Author: Artem Konovalov, 2017-06-05 09:58:00