2016-10-11 7 views
0

NaClラッパーを試してみました。私のサーバーでKaliumを使用し、クライアント側でlibsodium.jsを使用していますが、認証された暗号化を使用して2つのエンド間で通信しようとすると、暗号テキストが検証に失敗します。ナンス、serverPublicKeyBytesとclientPrivateKeyがサーバーにBase64で文字列として転送されサーバで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); 

:クライアント上 暗号化をすることによって行われます。サーバーで

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; 
    } 

をJavascriptをUInt8Array []は、誰かがクライアント - を有効にするには、私を支援することができます使用して、サーバー上の間、ラッパーは[] Javaのバイトを使用しています:データを使用して復号化されたサーバーで

サーバー通信。事前

答えて

0

おかげで多くの試行錯誤の後、私はカリウムのデフォルトBoxクラスは

クローン環境にカリウムプロジェクトと... sodium.crypto_box_easyのJavaScriptのバージョンでは動作しないことが判明しましたBoxクラスのいずれかで、このコードを呼び出すか、独自のクラスを作成し、その後

public int crypto_box_easy(@Out byte[] ciphertext, @In byte[] plaintext, @In @u_int64_t int plaintextLength, 
       @In byte[] nonce, @In byte[] receiverPublicKey, @In byte[] senderPrivateKey); 

     public int crypto_box_open_easy(@Out byte[] plaintext, @In byte[] ciphertext, 
       @In @u_int64_t int ciphertextLength, @In byte[] nonce, @In byte[] senderPublicKey, 
       @In byte[] receiverPrivateKey); 

そして:クラスのNaClに次のコードを追加します

isValid(sodium().crypto_box_easy(ciphertext, plaintext, plaintext.length, nonce, receiverPublicKey, 
       senderPrivateKey), "Encryption failed"); 
isValid(sodium().crypto_box_open_easy(plaintext, ciphertext, ciphertext.length, nonce, senderPublicKey, 
      receiverPrivateKey), "Decryption failed. Ciphertext failed verification."); 

上記コード(crypto_box_easy)で暗号文は、新しいバイト[] を有する物体長= crypto_box_curve25519xsalsa20poly1305_MACBYTES(16)+平文長さです。 上記のコードの平文(crypto_box_open_easy)は、長さが元の平文の長さがである新しいbyte []オブジェクトです。

関連する問題