指定された公開鍵で迅速なナトリウムを使用して値を暗号化しようとしています。ただし、暗号化された値は、サーバー側で生成されるものと同じではありません。このコーディングが迅速に正しいかどうかはわかりません。手順は、Java で行う方法と似ています。
公開鍵が base64 文字列形式であると仮定します。
ジャワ:
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))
迅速な同等のコーディングの何が問題なのか教えてください。どうもありがとう。