Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSM-486 - Java SDK - Fixed missing PKCS7Padding with SUN provider in Java #556

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,17 @@ internal fun hash(data: ByteArray, tag: String): ByteArray {
}

internal fun getCipher(mode: Int, iv: ByteArray, key: ByteArray, useCBC: Boolean = false): Cipher {
val transformation = if (useCBC) "AES/CBC/PKCS7Padding" else "AES/GCM/NoPadding"
// Some cryptographic libraries such as the SUN provider in Java indicate PKCS#5 where PKCS#7 should be used
val paddingProvider = if (KeeperCryptoParameters.provider == null) "AES/CBC/PKCS5Padding" else "AES/CBC/PKCS7Padding"
val transformation = if (useCBC) paddingProvider else "AES/GCM/NoPadding"
val cipher = if (KeeperCryptoParameters.provider == null)
Cipher.getInstance(transformation) else
Cipher.getInstance(transformation, KeeperCryptoParameters.provider)

val keySpec = SecretKeySpec(key, "AES")
val gcmParameterSpec = GCMParameterSpec(16 * 8, iv)
cipher.init(mode, keySpec, gcmParameterSpec)
val parameterSpec = if (useCBC) IvParameterSpec(iv) else GCMParameterSpec(16 * 8, iv)
cipher.init(mode, keySpec, parameterSpec)

return cipher
}

Expand Down
Loading