Search in sources :

Example 31 with Digest

use of org.bouncycastle.crypto.Digest in project nem2-sdk-java by nemtech.

the class Hashes method sha256ForSharedKey.

/**
 * Hasher used for shared keys
 *
 * @param sharedSecret the shared secret
 * @return the shared key hash.
 */
public static byte[] sha256ForSharedKey(byte[] sharedSecret) {
    Digest hash = new SHA256Digest();
    byte[] info = "catapult".getBytes();
    int length = 32;
    byte[] sharedKey = new byte[length];
    HKDFParameters params = new HKDFParameters(sharedSecret, null, info);
    HKDFBytesGenerator hkdf = new HKDFBytesGenerator(hash);
    hkdf.init(params);
    hkdf.generateBytes(sharedKey, 0, length);
    return sharedKey;
}
Also used : HKDFBytesGenerator(org.bouncycastle.crypto.generators.HKDFBytesGenerator) MessageDigest(java.security.MessageDigest) Digest(org.bouncycastle.crypto.Digest) SHA256Digest(org.bouncycastle.crypto.digests.SHA256Digest) SHA256Digest(org.bouncycastle.crypto.digests.SHA256Digest) HKDFParameters(org.bouncycastle.crypto.params.HKDFParameters)

Aggregations

Digest (org.bouncycastle.crypto.Digest)31 SHA256Digest (org.bouncycastle.crypto.digests.SHA256Digest)9 SHA1Digest (org.bouncycastle.crypto.digests.SHA1Digest)8 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)5 RSABlindedEngine (org.bouncycastle.crypto.engines.RSABlindedEngine)5 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)4 OAEPEncoding (org.bouncycastle.crypto.encodings.OAEPEncoding)4 InvalidParameterException (java.security.InvalidParameterException)3 BigInteger (java.math.BigInteger)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidKeyException (java.security.InvalidKeyException)2 SecureRandom (java.security.SecureRandom)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)2 CipherParameters (org.bouncycastle.crypto.CipherParameters)2 DSAParameters (org.bouncycastle.crypto.params.DSAParameters)2 DSAValidationParameters (org.bouncycastle.crypto.params.DSAValidationParameters)2 ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)2