PKCS7Padding is deprecated in Java 8

This commit is contained in:
Davide Depau 2020-11-30 23:54:51 +01:00
parent f53d947a13
commit 5d438daf83

View file

@ -17,10 +17,10 @@ class Aes {
val key = generateKey()
val seed = SecureRandom().generateSeed(16)
val iv = IvParameterSpec(seed)
encryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding").apply {
encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding").apply {
init(Cipher.ENCRYPT_MODE, key, iv)
}
decryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding").apply {
decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding").apply {
init(Cipher.DECRYPT_MODE, key, iv)
}
} catch (e: Exception) {
@ -32,10 +32,10 @@ class Aes {
try {
val key = SecretKeySpec(keyArr, "AES")
val iv = IvParameterSpec(ivArr)
encryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding").apply {
encryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding").apply {
init(Cipher.ENCRYPT_MODE, key, iv)
}
decryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding").apply {
decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding").apply {
init(Cipher.DECRYPT_MODE, key, iv)
}
} catch (e: NoSuchAlgorithmException) {