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"); } }
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"); } }
private void shouldPassSignatureTest2() throws Exception { BigInteger n = new BigInteger("b746ba6c3c0be64bbe33aa55b2929b0af4e86d773d44bfe5914db9287788c4663984b61a418d2eecca30d752ff6b620a07ec72eeb2b422d2429da352407b99982800b9dd7697be6a7b1baa98ca5f4fc2fe33400f20b9dba337ac25c987804165d4a6e0ee4d18eabd6de5abdfe578cae6713ff91d16c80a5bb20217fe614d9509e75a43e1825327b9da8f0a9f6eeaa1c04b69fb4bacc073569fff4ab491becbe6d0441d437fc3fa823239c4a0f75321666b68dd3f66e2dd394089a15bcc288a68a4eb0a48e17d639743b9dea0a91cc35820544732aff253f8ca9967c609dc01c2f8cd0313a7a91cfa94ff74289a1d2b6f19d1811f4b9a65f4cce9e5759b4cc64f", 16); BigInteger e = new BigInteger("dcbbdb", 16); byte[] msg = Hex.decode("a5d3c8a060f897bbbc20ae0955052f37fbc70986b6e11c65075c9f457142bfa93856897c69020aa81a91b5e4f39e05cdeecc63395ab849c8262ca8bc5c96870aecb8edb0aba0024a9bdb71e06de6100344e5c318bc979ef32b8a49a8278ba99d4861bce42ebbc5c8c666aaa6cac39aff8779f2cae367620f9edd4cb1d80b6c8c"); byte[] sig = Hex.decode("39fbbd1804c689a533b0043f84da0f06081038c0fbf31e443e46a05e58f50de5198bbca40522afefaba3aed7082a6cb93b1da39f1f5a42246bf64930781948d300549bef0f8d554ecfca60a1b1ecba95a7014ee4545ad4f0c4e3a31942c6738b4ccd6244b6a21267dadf0826a5f713f13b1f5a9ab8501d957a26d4948278ac67851071a315674bdab173bfef2c2690c8373da6bf3d69f30c0e5da8883de872f59521b40793854085641adf98d13db991c5d0a8aaa0222934fa33332e90ef0b954e195cb267d6ffb36c96e14d1ec7b915a87598b4461a3146566354dc2ae748c84ee0cd46543b53ebff8cdf47725b280a1f799fb6ebb4a31ad2bdd5178250f83a"); RSAKeyParameters rsaPublic = new RSAKeyParameters(false, n, e); X931Signer signer = new X931Signer(new RSAEngine(), new SHA224Digest()); signer.init(false, rsaPublic); signer.update(msg, 0, msg.length); if (!signer.verifySignature(sig)) { fail("RSA X931 verify test 2 failed."); } }
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 SHA224Digest((SHA224Digest)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; }
public static void bcSHA224() { Digest digest = new SHA224Digest(); digest.update(src.getBytes(), 0, src.getBytes().length ); byte[] sha224Bytes = new byte[digest.getDigestSize()]; digest.doFinal(sha224Bytes, 0); System.out.println("bc sha-224:" + org.bouncycastle.util.encoders.Hex.toHexString(sha224Bytes)); }
public void performTest() { RainbowParameters params = new RainbowParameters(); RainbowKeyPairGenerator rainbowKeyGen = new RainbowKeyPairGenerator(); RainbowKeyGenerationParameters genParam = new RainbowKeyGenerationParameters(keyRandom, params); rainbowKeyGen.init(genParam); AsymmetricCipherKeyPair pair = rainbowKeyGen.generateKeyPair(); ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), keyRandom); DigestingMessageSigner rainbowSigner = new DigestingMessageSigner(new RainbowSigner() , new SHA224Digest()); rainbowSigner.init(true, param); byte[] message = BigIntegers.asUnsignedByteArray(new BigInteger("968236873715988614170569073515315707566766479517")); rainbowSigner.update(message, 0, message.length); byte[] sig = rainbowSigner.generateSignature(); rainbowSigner.init(false, pair.getPublic()); rainbowSigner.update(message, 0, message.length); if (!rainbowSigner.verify(sig)) { fail("verification fails"); } }
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 withSha224() { super(new SHA224Digest(), new RainbowSigner()); }
public McElieceKobaraImai224() { super(new SHA224Digest(), new McElieceKobaraImaiCipher()); }
public McElieceFujisaki224() { super(new SHA224Digest(), new McElieceFujisakiCipher()); }