List of usage examples for org.bouncycastle.crypto.digests SHA256Digest SHA256Digest
public SHA256Digest()
From source file:secret.sharing.Encryptor.java
License:Open Source License
/** * Initiate the HMAC generator/*w ww . j av a 2s.c o m*/ * @param passphrase string used for encryption / decryption and authentification * @param hmacSalt salt for HMAC key */ private void initHMAC(String passphrase, byte[] hmacSalt) throws NoSuchAlgorithmException, InvalidKeySpecException { byte[] hmacKey = deriveKey(passphrase, hmacSalt, mHMACKeySize); mHmac = new HMac(new SHA256Digest()); mHmac.init(new KeyParameter(hmacKey)); mHMAC = null; }
From source file:us.eharning.atomun.core.ec.internal.BouncyCastleECKeyPair.java
License:Apache License
/** * Perform an ECDSA signature using the private key. * * @param hash// w w w . jav a 2 s . c om * byte array to sign. * * @return ASN.1 representation of the signature. */ @Nonnull @Override public byte[] sign(@Nonnull byte[] hash) { /* The HMacDSAKCalculator is what makes this signer RFC 6979 compliant. */ ECDSASigner signer = new ECDSASigner(new RFC6979KCalculator(new SHA256Digest())); signer.init(true, new ECPrivateKeyParameters(privateExponent, domain)); BigInteger[] signature = signer.generateSignature(hash); ByteArrayOutputStream stream = new ByteArrayOutputStream(); /* Need to canonicalize signature up front ... */ if (CANONICALIZE && signature[1].compareTo(HALF_CURVE_ORDER) > 0) { /* BOP does not do this */ signature[1] = curve.getN().subtract(signature[1]); } try { DERSequenceGenerator seq = new DERSequenceGenerator(stream); seq.addObject(new ASN1Integer(signature[0])); seq.addObject(new ASN1Integer(signature[1])); seq.close(); return stream.toByteArray(); } catch (IOException e) { throw new IllegalStateException("IOException should not be thrown", e); } }