コード例 #1
0
ファイル: SecretBox.java プロジェクト: duniter/duniter4j
 public byte[] encrypt(byte[] nonce, byte[] message) {
   checkLength(nonce, XSALSA20_POLY1305_SECRETBOX_NONCEBYTES);
   byte[] msg = Util.prependZeros(ZERO_BYTES, message);
   byte[] ct = Util.zeros(msg.length);
   isValid(
       sodium().crypto_secretbox_xsalsa20poly1305(ct, msg, msg.length, nonce, seed),
       "Encryption failed");
   return removeZeros(BOXZERO_BYTES, ct);
 }
コード例 #2
0
ファイル: SecretBox.java プロジェクト: duniter/duniter4j
 public byte[] decrypt(byte[] nonce, byte[] ciphertext) {
   checkLength(nonce, XSALSA20_POLY1305_SECRETBOX_NONCEBYTES);
   byte[] ct = Util.prependZeros(BOXZERO_BYTES, ciphertext);
   byte[] message = Util.zeros(ct.length);
   isValid(
       sodium().crypto_secretbox_xsalsa20poly1305_open(message, ct, ct.length, nonce, seed),
       "Decryption failed. Ciphertext failed verification");
   return removeZeros(ZERO_BYTES, message);
 }
コード例 #3
0
ファイル: SecretBox.java プロジェクト: duniter/duniter4j
  public byte[] sign(byte[] message) {
    byte[] signature = Util.prependZeros(SIGNATURE_BYTES, message);
    LongLongByReference bufferLen = new LongLongByReference(0);
    sodium().crypto_sign_ed25519(signature, bufferLen, message, message.length, secretKey);
    signature = Util.slice(signature, 0, SIGNATURE_BYTES);

    checkLength(signature, SIGNATURE_BYTES);
    return signature;
  }
コード例 #4
0
 public byte[] sign(byte[] message) {
   byte[] signature = Util.prependZeros(SIGNATURE_BYTES, message);
   int[] bufferLen = new int[1];
   sodium().crypto_sign_ed25519(signature, bufferLen, message, message.length, secretKey);
   signature = slice(signature, 0, SIGNATURE_BYTES);
   return signature;
 }