rspec/rules/S5547/kotlin/how-to-fix-it/java-cryptography-extension.adoc
Loris S 96811524d7
Modify JVM Crypto rules: Change framework name (#3550)
* Modify JVM Crypto rules: Change title

* changed names

* Apply suggestions from code review

* fixed includes
2024-01-25 15:18:07 +01:00

49 lines
1.0 KiB
Plaintext

== How to fix it in Java Cryptography Extension
=== Code examples
include::../../common/fix/code-rationale.adoc[]
==== Noncompliant code example
[source,kotlin,diff-id=1,diff-type=noncompliant]
----
import javax.crypto.NoSuchPaddingException
import java.security.NoSuchAlgorithmException
import javax.crypto.Cipher
fun main(args: Array<String>) {
try {
val des = Cipher.getInstance("DES") // Noncompliant
} catch (e: NoSuchAlgorithmException) {
// ...
} catch (e: NoSuchPaddingException) {
// ...
}
}
----
==== Compliant solution
[source,kotlin,diff-id=1,diff-type=compliant]
----
import javax.crypto.NoSuchPaddingException
import java.security.NoSuchAlgorithmException
import javax.crypto.Cipher
fun main(args: Array<String>) {
try {
val aes = Cipher.getInstance("AES/GCM/NoPadding")
} catch (e: NoSuchAlgorithmException) {
// ...
} catch (e: NoSuchPaddingException) {
// ...
}
}
----
=== How does this work?
include::../../common/fix/strong-cryptography.adoc[]