public Box(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; checkLength(publicKey, PUBLICKEY_BYTES); checkLength(privateKey, SECRETKEY_BYTES); }
public Box(byte[] publicKey, byte[] privateKey) { this.publicKey = publicKey; this.privateKey = privateKey; checkLength(publicKey, PUBLICKEY_BYTES); checkLength(privateKey, SECRETKEY_BYTES); }
public VerifyKey(byte[] key) { Util.checkLength(key, PUBLICKEY_BYTES); this.key = key; }
public PublicKey(byte[] publicKey) { this.publicKey = publicKey; Util.checkLength(publicKey, PUBLICKEY_BYTES); }
public PrivateKey(byte[] secretKey) { this.secretKey = secretKey; checkLength(secretKey, SECRETKEY_BYTES); }
public PrivateKey(String secretKey) { this.secretKey = HEX.decode(secretKey); checkLength(this.secretKey, SECRETKEY_BYTES); }
public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, NONCE_BYTES); byte[] msg = prependZeros(ZERO_BYTES, message); byte[] ct = new byte[msg.length]; isValid(sodium().crypto_box_curve25519xsalsa20poly1305(ct, msg, msg.length, nonce, publicKey, privateKey), "Encryption failed"); return removeZeros(BOXZERO_BYTES, ct); }
public byte[] decrypt(byte[] nonce, byte[] ciphertext) { checkLength(nonce, NONCE_BYTES); byte[] ct = prependZeros(BOXZERO_BYTES, ciphertext); byte[] message = new byte[ct.length]; isValid(sodium().crypto_box_curve25519xsalsa20poly1305_open(message, ct, message.length, nonce, publicKey, privateKey), "Decryption failed. Ciphertext failed verification."); return removeZeros(ZERO_BYTES, message); }
public KeyPair(byte[] seed){ Util.checkLength(seed, SECRETKEY_BYTES); this.seed = seed; this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); Util.isValid(sodium().crypto_box_curve25519xsalsa20poly1305_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); }
public byte[] decrypt(byte[] nonce, byte[] ciphertext) { checkLength(nonce, NONCE_BYTES); byte[] ct = prependZeros(BOXZERO_BYTES, ciphertext); byte[] message = new byte[ct.length]; isValid(sodium().crypto_box_curve25519xsalsa20poly1305_open(message, ct, message.length, nonce, publicKey, privateKey), "Decryption failed. Ciphertext failed verification."); return removeZeros(ZERO_BYTES, message); }
public boolean verify(byte[] message, byte[] signature) { Util.checkLength(signature, SIGNATURE_BYTES); byte[] sigAndMsg = Util.merge(signature, message); byte[] buffer = Util.zeros(sigAndMsg.length); int[] bufferLen = new int[1]; return Util.isValid(sodium().crypto_sign_ed25519_open(buffer, bufferLen, sigAndMsg, sigAndMsg.length, key), "signature was forged or corrupted"); }
public KeyPair(byte[] seed){ Util.checkLength(seed, SECRETKEY_BYTES); this.seed = seed; this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); Util.isValid(sodium().crypto_box_curve25519xsalsa20poly1305_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); }
public byte[] encrypt(byte[] nonce, byte[] message) { checkLength(nonce, NONCE_BYTES); byte[] msg = prependZeros(ZERO_BYTES, message); byte[] ct = new byte[msg.length]; isValid(sodium().crypto_box_curve25519xsalsa20poly1305(ct, msg, msg.length, nonce, publicKey, privateKey), "Encryption failed"); return removeZeros(BOXZERO_BYTES, ct); }
public boolean verify(byte[] message, byte[] signature) { Util.checkLength(signature, SIGNATURE_BYTES); byte[] sigAndMsg = Util.merge(signature, message); byte[] buffer = Util.zeros(sigAndMsg.length); int[] bufferLen = new int[1]; return Util.isValid(sodium().crypto_sign_ed25519_open(buffer, bufferLen, sigAndMsg, sigAndMsg.length, key), "signature was forged or corrupted"); }
public SigningKey(byte[] seed) { Util.checkLength(seed, SECRETKEY_BYTES); this.seed = seed; this.secretKey = Util.zeros(SECRETKEY_BYTES * 2); byte[] publicKey = Util.zeros(PUBLICKEY_BYTES); Util.isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); }
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, key), "Encryption failed"); return removeZeros(BOXZERO_BYTES, ct); }
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, key), "Encryption failed"); return removeZeros(BOXZERO_BYTES, ct); }
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, key), "Decryption failed. Ciphertext failed verification"); return removeZeros(ZERO_BYTES, message); } }
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, key), "Decryption failed. Ciphertext failed verification"); return removeZeros(ZERO_BYTES, message); } }
public SigningKey(byte[] seed) { Util.checkLength(seed, SECRETKEY_BYTES); this.seed = seed; this.secretKey = Util.zeros(SECRETKEY_BYTES * 2); byte[] publicKey = Util.zeros(PUBLICKEY_BYTES); Util.isValid(sodium().crypto_sign_ed25519_seed_keypair(publicKey, secretKey, seed), "Failed to generate a key pair"); this.verifyKey = new VerifyKey(publicKey); }