示例#1
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);
 }
示例#2
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);
 }
示例#3
0
 public SecretBox(byte[] seed) {
   checkLength(seed, SEED_LENGTH);
   this.seed = seed;
   this.secretKey = CryptoUtils.zeros(SECRETKEY_BYTES * 2);
   byte[] publicKey = CryptoUtils.zeros(PUBLICKEY_BYTES);
   isValid(
       sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed),
       "Failed to generate a key pair");
   this.pubKey = Base58.encode(publicKey);
 }
  public SigningKey(byte[] seed) {
    checkLength(seed, SECRETKEY_BYTES);
    this.seed = seed;
    this.secretKey = zeros(SECRETKEY_BYTES * 2);
    byte[] publicKey = zeros(PUBLICKEY_BYTES);
    isValid(
        sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed),
        "Failed to generate a key pair");

    this.verifyKey = new VerifyKey(publicKey);
  }