public byte[] sha256(byte[] message) { buffer = new byte[SodiumConstants.SHA256BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; }
public byte[] randomBytes() { byte[] buffer = new byte[DEFAULT_SIZE]; sodium().randombytes(buffer, DEFAULT_SIZE); return buffer; } }
public byte[] sha512(byte[] message) { buffer = new byte[SodiumConstants.SHA512BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
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[] 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, 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 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[] 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 = Util.slice(signature, 0, SIGNATURE_BYTES); return signature; }
public KeyPair() { this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); }
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 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"); }
/** * Generate random bytes * * @param n number or random bytes * @return Byte array with random bytes */ public byte[] randomBytes(int n) { byte[] buffer = new byte[n]; sodium().randombytes(buffer, n); return buffer; }
public KeyPair() { this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); }
public byte[] sha256(byte[] message) { buffer = new byte[SodiumConstants.SHA256BYTES]; sodium().crypto_hash_sha256(buffer, message, message.length); return buffer; }
public byte[] sha512(byte[] message) { buffer = new byte[SodiumConstants.SHA512BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
/** * Generate random bytes * * @param n number or random bytes * @return Byte array with random bytes */ public byte[] randomBytes(int n) { byte[] buffer = new byte[n]; sodium().randombytes(buffer, n); return buffer; }
public byte[] randomBytes() { byte[] buffer = new byte[DEFAULT_SIZE]; sodium().randombytes(buffer, DEFAULT_SIZE); return buffer; } }