use of javax.crypto.NoSuchPaddingException in project lzc_app_lib by httplzc.
the class RSAUtils method decryptByPrivateKey.
/**
* 107. * 私钥解密
* 108. *
* 109. * @param data
* 110. * @param privateKey
* 111. * @return
* 112. * @throws Exception
* 113.
*/
public static String decryptByPrivateKey(byte[] data, RSAPrivateKey privateKey) {
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
return new String(cipher.doFinal(data));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project lzc_app_lib by httplzc.
the class RSAUtils method encryptByPublicKey.
// 加密
public static byte[] encryptByPublicKey(String data, RSAPublicKey publicKey) {
try {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return cipher.doFinal(data.getBytes());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project EssayJoke by qiyei2015.
the class AES method decrypt.
/**
* AES解密
* @param rules 规则
* @param encryptText 密文
* @return 解密后的明文
*/
public static byte[] decrypt(String rules, byte[] encryptText) {
if (TextUtils.isEmpty(rules)) {
return null;
}
if (encryptText == null || encryptText.length == 0) {
return null;
}
try {
SecretKeySpec key = generateSecretKey(rules);
if (key != null) {
// 6.根据指定算法AES自成密码器
Cipher cipher = Cipher.getInstance("AES");
// 7.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(Cipher.DECRYPT_MODE, key);
// 8. 解密
byte[] byteDecode = cipher.doFinal(encryptText);
return byteDecode;
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project EssayJoke by qiyei2015.
the class AES method encrypt.
/**
* AES加密
* @param rules 规则
* @param plainText 明文
* @return 加密后的密文
*/
public static byte[] encrypt(String rules, String plainText) {
if (TextUtils.isEmpty(rules)) {
return null;
}
if (plainText == null || plainText.length() == 0) {
return null;
}
try {
SecretKeySpec key = generateSecretKey(rules);
if (key != null) {
// 1.根据指定算法AES自成密码器
Cipher cipher = Cipher.getInstance("AES");
// 2.初始化密码器,第一个参数为加密(Encrypt_mode)或者解密(Decrypt_mode)操作,第二个参数为使用的KEY
cipher.init(Cipher.ENCRYPT_MODE, key);
// 3. 加密
byte[] byteEncode = cipher.doFinal(plainText.getBytes("utf-8"));
return byteEncode;
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
use of javax.crypto.NoSuchPaddingException in project remusic by aa112901.
the class Aes method decrypt.
private static byte[] decrypt(byte[] content, String password) {
try {
byte[] keyStr = getKey(password);
SecretKeySpec key = new SecretKeySpec(keyStr, "AES");
// algorithmStr
Cipher cipher = Cipher.getInstance(algorithmStr);
// ʼ
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] result = cipher.doFinal(content);
//
return result;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IllegalBlockSizeException e) {
e.printStackTrace();
} catch (BadPaddingException e) {
e.printStackTrace();
}
return null;
}
Aggregations