0
我想用給定的公鑰加密使用swift鈉的值。 但是,加密值與服務器端生成的值不同。 我不確定這段代碼是否正確無誤。 這些步驟與在java中完成的步驟類似。Swift鈉 - 匿名加密(密封盒)
假設公鑰採用base64字符串格式。
的Java:
String pubKey = "w6mjd11n9w9ncKfcuR888Ygi02ou+46ocIajlcUEmQ=";
String secret = "hithere"
byte[] pubKeyBytes = Base64.decode(pubKey,0);
SealedBox sealedDeal = new SealedBox(pubKeyBytes);
byte[] c = sealedDeal.encrypt(secret.getBytes());
String ciphertext = Base64.encodeToString(c, 0);
斯威夫特:
let pubKey = "w6mjd11n9w9ncKfcuR888Ygi02ou+46ocIajlcUEmQ="
let dataDecoded:NSData = NSData(base64Encoded: pubKey, options: NSData.Base64DecodingOptions(rawValue: 0))!
let secret = "hithere".toData()!
let c : Data = sodium.box.seal(message: secret, recipientPublicKey: dataDecoded as Box.PublicKey)!
let ciphertext = c.base64EncodedString(options: .init(rawValue: 0))
請告訴我知道什麼是錯的迅速相當於編碼。 非常感謝。