|
11 | 11 | import java.security.SecureRandom;
|
12 | 12 | import java.security.Security;
|
13 | 13 | import java.security.spec.ECGenParameterSpec;
|
14 |
| - |
15 | 14 | import java.util.Date;
|
16 | 15 | import java.util.Iterator;
|
17 | 16 |
|
|
33 | 32 | import org.bouncycastle.crypto.params.KeyParameter;
|
34 | 33 | import org.bouncycastle.crypto.params.X25519PrivateKeyParameters;
|
35 | 34 | import org.bouncycastle.crypto.params.X25519PublicKeyParameters;
|
36 |
| -import org.bouncycastle.jcajce.provider.asymmetric.edec.KeyAgreementSpi; |
37 | 35 | import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
38 | 36 | import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
|
39 | 37 | import org.bouncycastle.openpgp.PGPEncryptedData;
|
|
55 | 53 | import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory;
|
56 | 54 | import org.bouncycastle.openpgp.operator.PGPContentVerifier;
|
57 | 55 | import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
|
| 56 | +import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider; |
58 | 57 | import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
|
59 | 58 | import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
|
60 | 59 | import org.bouncycastle.openpgp.operator.bc.BcPGPDataEncryptorBuilder;
|
|
75 | 74 | import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
|
76 | 75 | import org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
|
77 | 76 | import org.bouncycastle.util.Arrays;
|
| 77 | +import org.bouncycastle.util.Strings; |
78 | 78 | import org.bouncycastle.util.encoders.Hex;
|
79 | 79 | import org.bouncycastle.util.test.SimpleTest;
|
80 | 80 | import org.bouncycastle.util.test.UncloseableOutputStream;
|
@@ -106,6 +106,37 @@ public void performTest()
|
106 | 106 | testBcPGPContentVerifierBuilderProvider();
|
107 | 107 | //testBcPBESecretKeyDecryptorBuilder();
|
108 | 108 | testBcKeyFingerprintCalculator();
|
| 109 | + testBcStandardDigests(); |
| 110 | + } |
| 111 | + |
| 112 | + private void testBcStandardDigests() |
| 113 | + throws Exception |
| 114 | + { |
| 115 | + PGPDigestCalculatorProvider digCalcBldr = new BcPGPDigestCalculatorProvider(); |
| 116 | + |
| 117 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.MD5), Hex.decode("900150983cd24fb0d6963f7d28e17f72")); |
| 118 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA1), Hex.decode("a9993e364706816aba3e25717850c26c9cd0d89d")); |
| 119 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.RIPEMD160), Hex.decode("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")); |
| 120 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA256), Hex.decode("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")); |
| 121 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA384), Hex.decode("cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7")); |
| 122 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA512), Hex.decode("ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f")); |
| 123 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA224), Hex.decode("23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7")); |
| 124 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA3_256), Hex.decode("3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532")); |
| 125 | + testDigestCalc(digCalcBldr.get(HashAlgorithmTags.SHA3_512), Hex.decode("b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0")); |
| 126 | + } |
| 127 | + |
| 128 | + private void testDigestCalc(PGPDigestCalculator digCalc, byte[] expected) |
| 129 | + throws IOException |
| 130 | + { |
| 131 | + OutputStream dOut = digCalc.getOutputStream(); |
| 132 | + |
| 133 | + dOut.write(Strings.toByteArray("abc")); |
| 134 | + |
| 135 | + dOut.close(); |
| 136 | + |
| 137 | + byte[] res = digCalc.getDigest(); |
| 138 | + |
| 139 | + isTrue(Arrays.areEqual(res, expected)); |
109 | 140 | }
|
110 | 141 |
|
111 | 142 | public void testBcKeyFingerprintCalculator()
|
|
0 commit comments