use of javax.crypto.spec.SecretKeySpec in project ETSMobile-Android2 by ApplETS.
the class SecurePreferences method decrypt.
private static String decrypt(String ciphertext) {
if (ciphertext == null || ciphertext.length() == 0) {
return ciphertext;
}
try {
final Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(SecurePreferences.sKey, "AES"));
return new String(cipher.doFinal(SecurePreferences.decode(ciphertext)), "UTF-8");
} catch (Exception e) {
Log.w(SecurePreferences.class.getName(), "decrypt", e);
return null;
}
}
use of javax.crypto.spec.SecretKeySpec in project ETSMobile-Android2 by ApplETS.
the class SecurePreferences method encrypt.
private static String encrypt(String cleartext) {
if (cleartext == null || cleartext.length() == 0) {
return cleartext;
}
try {
final Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(SecurePreferences.sKey, "AES"));
return SecurePreferences.encode(cipher.doFinal(cleartext.getBytes("UTF-8")));
} catch (Exception e) {
Log.w(SecurePreferences.class.getName(), "encrypt", e);
return null;
}
}
use of javax.crypto.spec.SecretKeySpec in project Gradle-demo by Arisono.
the class AESUtil method encryptAES.
/**
* 加密
* @throws Exception
*/
public static byte[] encryptAES(byte[] data, byte[] key) throws Exception {
//恢复密钥
SecretKey secretKey = new SecretKeySpec(key, "AES");
//Cipher完成加密
Cipher cipher = Cipher.getInstance("AES");
//根据密钥对cipher进行初始化
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
//加密
byte[] encrypt = cipher.doFinal(data);
return encrypt;
}
use of javax.crypto.spec.SecretKeySpec in project Gradle-demo by Arisono.
the class DESUtil method encryptDES.
/**
* 加密
* @throws Exception
*/
public static byte[] encryptDES(byte[] data, byte[] key) throws Exception {
//获得密钥
SecretKey secretKey = new SecretKeySpec(key, "DES");
//Cipher完成加密
Cipher cipher = Cipher.getInstance("DES");
//初始化cipher
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
//加密
byte[] encrypt = cipher.doFinal(data);
return encrypt;
}
use of javax.crypto.spec.SecretKeySpec in project Gradle-demo by Arisono.
the class DESede method decrypt3DES.
/**
* 解密
*/
public static byte[] decrypt3DES(byte[] data, byte[] key) throws Exception {
//恢复密钥
SecretKey secretKey = new SecretKeySpec(key, "DESede");
//Cipher完成解密
Cipher cipher = Cipher.getInstance("DESede");
//初始化cipher
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] plain = cipher.doFinal(data);
return plain;
}
Aggregations