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[] 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; }
/** * 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[] sha256(byte[] message) { buffer = new byte[SodiumConstants.SHA256BYTES]; sodium().crypto_hash_sha256(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[] sha512(byte[] message) { buffer = new byte[SodiumConstants.SHA512BYTES]; sodium().crypto_hash_sha512(buffer, message, message.length); return buffer; }
private SQRLStorage() { Grc_aesgcm.gcm_initialize(); NaCl.sodium(); }
public String pwhash_scryptsalsa208sha256(String passwd, Encoder encoder, byte[] salt, int opslimit, int memlimit) { buffer = new byte[KEY_LEN]; //sodium().crypto_pwhash(buffer, buffer.length, passwd.getBytes(), passwd.length(), salt, opslimit, memlimit,sodium().crypto_pwhash_alg_default()); sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd.getBytes(), passwd.length(), salt, opslimit, memlimit); return encoder.encode(buffer); }
public String pwhash_scryptsalsa208sha256(String passwd, Encoder encoder, byte[] salt, int opslimit, int memlimit) { buffer = new byte[KEY_LEN]; //sodium().crypto_pwhash(buffer, buffer.length, passwd.getBytes(), passwd.length(), salt, opslimit, memlimit,sodium().crypto_pwhash_alg_default()); sodium().crypto_pwhash_scryptsalsa208sha256(buffer, buffer.length, passwd.getBytes(), passwd.length(), salt, opslimit, memlimit); return encoder.encode(buffer); }
public byte[] blake2(byte[] message) throws UnsupportedOperationException { if (!blakeSupportedVersion()) throw new UnsupportedOperationException(); buffer = new byte[SodiumConstants.BLAKE2B_OUTBYTES]; sodium().crypto_generichash_blake2b(buffer, SodiumConstants.BLAKE2B_OUTBYTES, message, message.length, new byte[0], 0); return buffer; }
public byte[] blake2(byte[] message) throws UnsupportedOperationException { if (!blakeSupportedVersion()) throw new UnsupportedOperationException(); buffer = new byte[SodiumConstants.BLAKE2B_OUTBYTES]; sodium().crypto_generichash_blake2b(buffer, SodiumConstants.BLAKE2B_OUTBYTES, message, message.length, new byte[0], 0); return buffer; }
public KeyPair() { this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); }
public Point mult(byte[] n) { byte[] result = zeros(SCALAR_BYTES); sodium().crypto_scalarmult_curve25519(result, n, point); return new Point(result); }
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 Point mult(byte[] n) { byte[] result = zeros(SCALAR_BYTES); sodium().crypto_scalarmult_curve25519(result, n, point); return new Point(result); }
public KeyPair() { this.secretKey = zeros(SECRETKEY_BYTES); this.publicKey = zeros(PUBLICKEY_BYTES); sodium().crypto_box_curve25519xsalsa20poly1305_keypair(publicKey, secretKey); }
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 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"); }