【发布时间】:2020-08-26 10:27:20
【问题描述】:
我在 javascript 中使用 eccrypto 库使用 ECIES 算法 (curve-secp256k1) 进行加密。在 JS 代码中加密生成的密码在 Kotlin 中无法解密。
这里是 Javascript 代码。
var eccrypto = require("eccrypto");
eccrypto.encrypt(publicKeyA, Buffer.from("Sic Mundus Creatus Est")).then(function(encrypted) {
val ciphertext = encrypted.ciphertext
//the hex encoded ciphertext is then sent to the server
}
这里是kotlin的解密代码
val cipherBytes = DatatypeConverter.parseHexBinary(ciphertext)
val cipher: Cipher = Cipher.getInstance("ECIES", "BC")
cipher.init(Cipher.DECRYPT_MODE, privateKeyA)
print( cipher.doFinal(cipherBytes) )
使用此代码进行解密,我得到一个坏块异常。
但是,如果我只是使用Java进行加密和解密,则没有问题。此外,Javascript 中的加密和解密也可以正常工作。
我有什么遗漏吗?
【问题讨论】:
-
尝试在两个环境中加密一些东西,看看值是否匹配
-
如果这两个操作都只在 Javascript 或 Kotlin 中完成,则加密和解密周期可以正常工作。但是,一个加密不能被另一个解密。
-
在两种环境中使用相同的公钥加密相同的消息会产生不同的密码消息。
-
请提供完整示例以及密钥生成、密钥传输/编码步骤和密钥。
标签: encryption encryption-asymmetric ecies