public static final Digest createHash(int hashAlgorithm) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest(); case HashAlgorithm.sha1: return new SHA1Digest(); case HashAlgorithm.sha224: return new SHA224Digest(); case HashAlgorithm.sha256: return new SHA256Digest(); case HashAlgorithm.sha384: return new SHA384Digest(); case HashAlgorithm.sha512: return new SHA512Digest(); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
public static final Digest cloneHash(int hashAlgorithm, Digest hash) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest((MD5Digest)hash); case HashAlgorithm.sha1: return new SHA1Digest((SHA1Digest)hash); case HashAlgorithm.sha224: return new SHA224Digest((SHA224Digest)hash); case HashAlgorithm.sha256: return new SHA256Digest((SHA256Digest)hash); case HashAlgorithm.sha384: return new SHA384Digest((SHA384Digest)hash); case HashAlgorithm.sha512: return new SHA512Digest((SHA512Digest)hash); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
protected Digest createHMACDigest(int macAlgorithm) throws IOException { switch (macAlgorithm) { case MACAlgorithm._null: return null; case MACAlgorithm.hmac_md5: return new MD5Digest(); case MACAlgorithm.hmac_sha1: return new SHA1Digest(); case MACAlgorithm.hmac_sha256: return new SHA256Digest(); case MACAlgorithm.hmac_sha384: return new SHA384Digest(); case MACAlgorithm.hmac_sha512: return new SHA512Digest(); default: throw new TlsFatalAlert(AlertDescription.internal_error); } }
public static Digest createHash(short hashAlgorithm) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest(); case HashAlgorithm.sha1: return new SHA1Digest(); case HashAlgorithm.sha224: return new SHA224Digest(); case HashAlgorithm.sha256: return new SHA256Digest(); case HashAlgorithm.sha384: return new SHA384Digest(); case HashAlgorithm.sha512: return new SHA512Digest(); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
public static Digest cloneHash(short hashAlgorithm, Digest hash) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest((MD5Digest)hash); case HashAlgorithm.sha1: return new SHA1Digest((SHA1Digest)hash); case HashAlgorithm.sha224: return new SHA224Digest((SHA224Digest)hash); case HashAlgorithm.sha256: return new SHA256Digest((SHA256Digest)hash); case HashAlgorithm.sha384: return new SHA384Digest((SHA384Digest)hash); case HashAlgorithm.sha512: return new SHA512Digest((SHA512Digest)hash); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
@Test public void curveTest() { final X9ECParameters curve = NISTNamedCurves.getByName("P-384"); final ECDomainParameters domainParameters = new ECDomainParameters( curve.getCurve(), curve.getG(), curve.getN()); final SecureRandom random = new SecureRandom(); final ECKeyPairGenerator gen = new ECKeyPairGenerator(); gen.init(new ECKeyGenerationParameters(domainParameters, random)); final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair(); final ECDSASigner signer = new ECDSASigner(); signer.init(true, senderPair.getPrivate()); final byte[] message = "The magic words are squeamish ossifrage".getBytes( Constants.ASCII); final SHA384Digest digester = new SHA384Digest(); digester.update(message, 0, message.length); final byte[] digest = new byte[digester.getDigestSize()]; digester.doFinal(digest, 0); final BigInteger[] signature = signer.generateSignature(digest); final ECDSASigner verifier = new ECDSASigner(); verifier.init(false, senderPair.getPublic()); assertTrue(verifier.verifySignature(digest, signature[0], signature[1])); }
public static final Digest createHash(short hashAlgorithm) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest(); case HashAlgorithm.sha1: return new SHA1Digest(); case HashAlgorithm.sha224: return new SHA224Digest(); case HashAlgorithm.sha256: return new SHA256Digest(); case HashAlgorithm.sha384: return new SHA384Digest(); case HashAlgorithm.sha512: return new SHA512Digest(); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
public static final Digest cloneHash(short hashAlgorithm, Digest hash) { switch (hashAlgorithm) { case HashAlgorithm.md5: return new MD5Digest((MD5Digest)hash); case HashAlgorithm.sha1: return new SHA1Digest((SHA1Digest)hash); case HashAlgorithm.sha224: return new SHA224Digest((SHA224Digest)hash); case HashAlgorithm.sha256: return new SHA256Digest((SHA256Digest)hash); case HashAlgorithm.sha384: return new SHA384Digest((SHA384Digest)hash); case HashAlgorithm.sha512: return new SHA512Digest((SHA512Digest)hash); default: throw new IllegalArgumentException("unknown HashAlgorithm"); } }
private Digest guessDigest(int size) { switch (size) { case 20: return new SHA1Digest(); case 28: return new SHA224Digest(); case 32: return new SHA256Digest(); case 48: return new SHA384Digest(); case 64: return new SHA512Digest(); } return null; }
public static Digest getDigest( String digestName) { digestName = Strings.toUpperCase(digestName); if (sha1.contains(digestName)) { return new SHA1Digest(); } if (md5.contains(digestName)) { return new MD5Digest(); } if (sha224.contains(digestName)) { return new SHA224Digest(); } if (sha256.contains(digestName)) { return new SHA256Digest(); } if (sha384.contains(digestName)) { return new SHA384Digest(); } if (sha512.contains(digestName)) { return new SHA512Digest(); } return null; }
public Object clone() throws CloneNotSupportedException { Digest d = (Digest)super.clone(); d.digest = new SHA384Digest((SHA384Digest)digest); return d; }
static Digest createDigest(int algorithm) throws PGPException { switch (algorithm) { case HashAlgorithmTags.SHA1: return new SHA1Digest(); case HashAlgorithmTags.SHA224: return new SHA224Digest(); case HashAlgorithmTags.SHA256: return new SHA256Digest(); case HashAlgorithmTags.SHA384: return new SHA384Digest(); case HashAlgorithmTags.SHA512: return new SHA512Digest(); case HashAlgorithmTags.MD2: return new MD2Digest(); case HashAlgorithmTags.MD5: return new MD5Digest(); case HashAlgorithmTags.RIPEMD160: return new RIPEMD160Digest(); case HashAlgorithmTags.TIGER_192: return new TigerDigest(); default: throw new PGPException("cannot recognise digest"); } }
private static void initDigesters() { digesters.put("Blake2b", Blake2bDigest.class); digesters.put("GOST3411", GOST3411Digest.class); digesters.put("Keccak", KeccakDigest.class); digesters.put("MD2", MD2Digest.class); digesters.put("MD4", MD4Digest.class); digesters.put("MD5", MD5Digest.class); digesters.put("RIPEMD128", RIPEMD128Digest.class); digesters.put("RIPEMD160", RIPEMD160Digest.class); digesters.put("RIPEMD256", RIPEMD256Digest.class); digesters.put("RIPEMD320", RIPEMD320Digest.class); digesters.put("SHA1", SHA1Digest.class); digesters.put("SHA224", SHA224Digest.class); digesters.put("SHA256", SHA256Digest.class); digesters.put("SHA384", SHA384Digest.class); digesters.put("SHA3-512", SHA3Digest.class); digesters.put("SHA3-256", SHA3Digest.class); digesters.put("SHA3-224", SHA3Digest.class); digesters.put("SHA3-384", SHA3Digest.class); digesters.put("SHA512", SHA512Digest.class); digesters.put("SHAKE-128", SHAKEDigest.class); digesters.put("SHAKE-256", SHAKEDigest.class); digesters.put("Skein256", SkeinDigest.class); digesters.put("Skein512", SkeinDigest.class); digesters.put("Skein1024", SkeinDigest.class); digesters.put("SM3", SM3Digest.class); digesters.put("Tiger", TigerDigest.class); digesters.put("Whirlpool", WhirlpoolDigest.class); }
public static Digest getDigest( String digestName) { digestName = Strings.toUpperCase(digestName); if (sha1.contains(digestName)) { return new SHA1Digest(); } if (md5.contains(digestName)) { return new MD5Digest(); } if (sha224.contains(digestName)) { return new SHA224Digest(); } if (sha256.contains(digestName)) { return new SHA256Digest(); } if (sha384.contains(digestName)) { return new SHA384Digest(); } if (sha512.contains(digestName)) { return new SHA512Digest(); } if (sha512_224.contains(digestName)) { return new SHA512tDigest(224); } if (sha512_256.contains(digestName)) { return new SHA512tDigest(256); } return null; }
/** * Creates a new SHA384 digest that may optionally be initialized with * random data. * * @param randomize * True to randomize initial state of digest, false otherwise. */ public SHA384(final boolean randomize) { super(new SHA384Digest()); if (randomize) { setRandomProvider(new SecureRandom()); setSalt(getRandomSalt()); } }
protected void engineSetParameter( AlgorithmParameterSpec params) throws InvalidParameterException { if (params instanceof PSSParameterSpec) { PSSParameterSpec newParamSpec = (PSSParameterSpec)params; this.engineParams = null; this.paramSpec = newParamSpec; this.saltLength = paramSpec.getSaltLength(); if (mgfDigest == null) { switch (saltLength) { case 20: this.mgfDigest = new SHA1Digest(); break; case 28: this.mgfDigest = new SHA224Digest(); break; case 32: this.mgfDigest = new SHA256Digest(); break; case 48: this.mgfDigest = new SHA384Digest(); break; case 64: this.mgfDigest = new SHA512Digest(); break; } setupContentDigest(); } } else { throw new InvalidParameterException("Only PSSParameterSpec supported"); } }
public withSha384() { super(new SHA384Digest(), new RainbowSigner()); }