【发布时间】:2016-10-11 12:51:59
【问题描述】:
我是尝试 NaCl 包装的新手。我在我的服务器上使用 Kalium,在我的客户端上使用 libsodium.js,它们都在工作,但是当我尝试使用经过身份验证的加密在两端之间进行通信时,密文验证失败。 客户端上的加密由:
var nonce=sodium.crypto_generichash(sodium.crypto_box_NONCEBYTES, dataObj.extensionId);
var message="test";
var encryptedString = sodium.crypto_box_easy(message, nonce, serverPublicKeyBytes, clientPrivateKey);
nonce、serverPublicKeyBytes 和 clientPrivateKey 作为 Base64 字符串传输到服务器。
在服务器中,数据被解密使用:
public byte[] decrypt( byte[] publicKey, byte[] privateKey, byte[] nonce,
byte[] message) throws Exception {
Box box = new Box(publicKey, privateKey);
byte[] output= box.decrypt(nonce, message);
return output;
}
在服务器中,包装器使用 java byte[],而在服务器上,javascript 使用 UInt8Array[],有人可以帮助我启用客户端-服务器通信。
提前致谢
【问题讨论】:
标签: javascript java encryption libsodium