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;
 }
예제 #2
0
 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);
 }
예제 #3
0
  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[] 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);
 }