public byte[] encrypt(String plaintext) throws EncryptionServiceException { try { byte[] newSalt = generateRandomArray(PBKDF2_SALT_SIZE_BYTES); SecretKey key = new SecretKeySpec(generateKey(newSalt), CIPHER); Cipher myCipher = Cipher.getInstance(CIPHERSCHEME); byte[] newNonce = generateRandomArray(GCM_IV_NONCE_SIZE_BYTES); GCMParameterSpec spec = new GCMParameterSpec(GCM_AUTHENTICATION_TAG_SIZE_BITS, newNonce); myCipher.init(Cipher.ENCRYPT_MODE, key, spec); byte[] bytes = plaintext.getBytes(); return Arrays.concatenate(newNonce, newSalt, myCipher.doFinal(bytes)); } catch (Exception e) { logger.error("Encryption failed", e); throw new EncryptionServiceException(e); } }
try { byte[] buf = readFile(file); byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes(UTF_8)); hashBuilder.setLength(0); hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest())));
private byte[] concatenate(byte[] header, byte[] id1, byte[] id2, byte[] ed1, byte[] ed2, byte[] text) { return Arrays.concatenate(Arrays.concatenate(header, id1, id2), Arrays.concatenate(ed1, ed2, text)); } }
/** * @return a new instance containing a copy of this instance followed by a copy of <code>tail</code>. */ public ByteArray concat(@NonNull ByteArray tail) { return new ByteArray(Arrays.concatenate(this.bytes, tail.bytes)); }
public int[] getCipherSuites() { return Arrays.concatenate(super.getCipherSuites(), new int[] { CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1, CipherSuite.TLS_ECDHE_RSA_WITH_SALSA20_SHA1, CipherSuite.TLS_RSA_WITH_ESTREAM_SALSA20_SHA1, CipherSuite.TLS_RSA_WITH_SALSA20_SHA1, }); }
static byte[] tweakFunction(long tweakValue) { byte[] bs = Pack.longToLittleEndian(tweakValue); return Arrays.concatenate(bs, bs); } private static final int BLOCK_SIZE = Property.DP_AESXTS_BLOCK_SIZE.asInteger().orElse(4096);
protected int[] getCipherSuites() { return Arrays.concatenate(super.getCipherSuites(), new int[] { CipherSuite.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, CipherSuite.TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1, CipherSuite.TLS_ECDHE_RSA_WITH_SALSA20_SHA1, CipherSuite.TLS_RSA_WITH_ESTREAM_SALSA20_SHA1, CipherSuite.TLS_RSA_WITH_SALSA20_SHA1, }); }
private byte[] wrapInResponse(final byte[] bytes) { String header = HttpFaker.getRandomResponseHeader(Http.RESPONSE_200, true); header = header.replaceAll(Matcher.quoteReplacement("$"), String.valueOf(bytes.length)); return Arrays.concatenate(header.getBytes(), bytes); }
private static byte[] generateDefaultPersonalizationString(byte[] seed) { return Arrays.concatenate(Strings.toByteArray("Default"), seed, Pack.longToBigEndian(Thread.currentThread().getId()), Pack.longToBigEndian(System.currentTimeMillis())); }
private static byte[] generateNonceIVPersonalizationString(byte[] seed) { return Arrays.concatenate(Strings.toByteArray("Nonce"), seed, Pack.longToLittleEndian(Thread.currentThread().getId()), Pack.longToLittleEndian(System.currentTimeMillis())); }
private byte[] encodeString(byte[] str) { if (str == null || str.length == 0) { return leftEncode(0); } return Arrays.concatenate(leftEncode(str.length * 8L), str); }
/** * Reseed the DRBG. * * @param additionalInput additional input to be added to the DRBG in this step. */ public void reseed(byte[] additionalInput) { byte[] entropy = getEntropy(); byte[] seedMaterial = Arrays.concatenate(entropy, additionalInput); hmac_DRBG_Update(seedMaterial); _reseedCounter = 1; }
private static String generateKeyFingerprint(BigInteger y, DHParameters dhParams) { return new Fingerprint( Arrays.concatenate( y.toByteArray(), dhParams.getP().toByteArray(), dhParams.getG().toByteArray())).toString(); } }
private static String generateKeyFingerprint(BigInteger y, GOST3410Parameters dhParams) { return new Fingerprint( Arrays.concatenate( y.toByteArray(), dhParams.getP().toByteArray(), dhParams.getA().toByteArray())).toString(); } }
static String generateKeyFingerprint(BigInteger y, DSAParams params) { return new Fingerprint(Arrays.concatenate(y.toByteArray(), params.getP().toByteArray(), params.getQ().toByteArray(), params.getG().toByteArray())).toString(); } }
private void CTR_DRBG_Instantiate_algorithm(byte[] entropy, byte[] nonce, byte[] personalisationString) { byte[] seedMaterial = Arrays.concatenate(entropy, nonce, personalisationString); byte[] seed = Block_Cipher_df(seedMaterial, _seedLength); int outlen = _engine.getBlockSize(); _Key = new byte[(_keySizeInBits + 7) / 8]; _V = new byte[outlen]; // _Key & _V are modified by this call CTR_DRBG_Update(seed, _Key, _V); _reseedCounter = 1; }
private void CTR_DRBG_Instantiate_algorithm(byte[] entropy, byte[] nonce, byte[] personalisationString) { byte[] seedMaterial = Arrays.concatenate(entropy, nonce, personalisationString); byte[] seed = Block_Cipher_df(seedMaterial, _seedLength); int outlen = _engine.getBlockSize(); _Key = new byte[(_keySizeInBits + 7) / 8]; _V = new byte[outlen]; // _Key & _V are modified by this call CTR_DRBG_Update(seed, _Key, _V); _reseedCounter = 1; }
private void CTR_DRBG_Reseed_algorithm(byte[] additionalInput) { byte[] seedMaterial = Arrays.concatenate(getEntropy(), additionalInput); seedMaterial = Block_Cipher_df(seedMaterial, _seedLength); CTR_DRBG_Update(seedMaterial, _Key, _V); _reseedCounter = 1; }
private byte[] PRF(TLSKeyMaterialSpec parameters, Mac prf) { byte[] label = Strings.toByteArray(parameters.getLabel()); byte[] labelSeed = Arrays.concatenate(label, parameters.getSeed()); byte[] secret = parameters.getSecret(); byte[] buf = new byte[parameters.getLength()]; hmac_hash(prf, secret, labelSeed, buf); return buf; } }
public static String generateKeyFingerprint(ECPoint publicPoint, org.bouncycastle.jce.spec.ECParameterSpec spec) { ECCurve curve = spec.getCurve(); ECPoint g = spec.getG(); if (curve != null) { return new Fingerprint(Arrays.concatenate(publicPoint.getEncoded(false), curve.getA().getEncoded(), curve.getB().getEncoded(), g.getEncoded(false))).toString(); } return new Fingerprint(publicPoint.getEncoded(false)).toString(); } }