I have this project wherein I have to convert nodeJs into Kotlin. The nodeJs project uses CryptoJS.AES.encrypt(text, password) which produces a encrypted value with 256 bytes. I. have been doing this in kotlin but the encrypted value returned is not the same from the nodeJs version and it only has 236 bytes. Can someone help me why it is not producing the same result? and how can i do it? Below is my sample code in kotlin
fun encryptAesTry(text: String, password: String): String {
val md = MessageDigest.getInstance("SHA-256")
val bytes = password.toByteArray(StandardCharsets.UTF_8)
md.update(bytes, 0, bytes.size)
val key = md.digest()
val secretKeySpec = SecretKeySpec(key, "AES")
val c = Cipher.getInstance("AES")
c.init(Cipher.ENCRYPT_MODE, secretKeySpec)
val encVal = c.doFinal(text.toByteArray())
return Base64.getEncoder().encodeToString(encVal)
}