The Android Open Source Project | b5de22c | 2012-04-01 00:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package libcore.java.security; |
| 18 | |
| 19 | import org.apache.harmony.xnet.provider.jsse.NativeCryptoTest; |
| 20 | import org.apache.harmony.xnet.provider.jsse.OpenSSLEngine; |
| 21 | import org.apache.harmony.xnet.provider.jsse.OpenSSLProvider; |
| 22 | |
| 23 | import java.math.BigInteger; |
| 24 | import java.security.InvalidKeyException; |
| 25 | import java.security.KeyFactory; |
| 26 | import java.security.KeyPair; |
| 27 | import java.security.KeyPairGenerator; |
| 28 | import java.security.PrivateKey; |
| 29 | import java.security.Provider; |
| 30 | import java.security.PublicKey; |
| 31 | import java.security.Security; |
| 32 | import java.security.Signature; |
| 33 | import java.security.SignatureException; |
| 34 | import java.security.interfaces.RSAPrivateKey; |
| 35 | import java.security.spec.DSAPrivateKeySpec; |
| 36 | import java.security.spec.DSAPublicKeySpec; |
| 37 | import java.security.spec.InvalidKeySpecException; |
| 38 | import java.security.spec.RSAPrivateCrtKeySpec; |
| 39 | import java.security.spec.RSAPrivateKeySpec; |
| 40 | import java.security.spec.RSAPublicKeySpec; |
| 41 | import java.security.spec.X509EncodedKeySpec; |
| 42 | import java.util.Arrays; |
| 43 | import java.util.HashMap; |
| 44 | import java.util.Map; |
| 45 | import java.util.Set; |
| 46 | |
| 47 | import junit.framework.TestCase; |
| 48 | |
| 49 | public class SignatureTest extends TestCase { |
| 50 | |
| 51 | // 20 bytes for DSA |
| 52 | private final byte[] DATA = new byte[20]; |
| 53 | |
| 54 | public void test_getInstance() throws Exception { |
| 55 | Provider[] providers = Security.getProviders(); |
| 56 | for (Provider provider : providers) { |
| 57 | Set<Provider.Service> services = provider.getServices(); |
| 58 | for (Provider.Service service : services) { |
| 59 | String type = service.getType(); |
| 60 | if (!type.equals("Signature")) { |
| 61 | continue; |
| 62 | } |
| 63 | String algorithm = service.getAlgorithm(); |
| 64 | try { |
| 65 | KeyPair kp = keyPair(algorithm, provider.getName()); |
| 66 | // Signature.getInstance(String) |
| 67 | Signature sig1 = Signature.getInstance(algorithm); |
| 68 | assertEquals(algorithm, sig1.getAlgorithm()); |
| 69 | test_Signature(sig1, kp); |
| 70 | |
| 71 | // Signature.getInstance(String, Provider) |
| 72 | Signature sig2 = Signature.getInstance(algorithm, provider); |
| 73 | assertEquals(algorithm, sig2.getAlgorithm()); |
| 74 | assertEquals(provider, sig2.getProvider()); |
| 75 | test_Signature(sig2, kp); |
| 76 | |
| 77 | // Signature.getInstance(String, String) |
| 78 | Signature sig3 = Signature.getInstance(algorithm, provider.getName()); |
| 79 | assertEquals(algorithm, sig3.getAlgorithm()); |
| 80 | assertEquals(provider, sig3.getProvider()); |
| 81 | test_Signature(sig3, kp); |
| 82 | } catch (Exception e) { |
| 83 | throw new Exception("Problem testing Signature." + algorithm, e); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public void test_getInstance_OpenSSL_ENGINE() throws Exception { |
| 90 | final String pem_private = "-----BEGIN RSA PRIVATE KEY-----\n" |
| 91 | + "MIICXAIBAAKBgQDpm4KamxulJnycEzNONGM7p0CvAaoZxJEd5Dvio5b6BROdCtRN\n" |
| 92 | + "lEsB+9vtB5thkyDVC7N+IW0AjtyDE6h2QP+AWa+c4dh0RM2uNVXkUWPrA8C++GHv\n" |
| 93 | + "EDlxZzRGiQEMuippYfIyBVkO+4+GRvnkG4dKjzxrQYPqKUK3C4PgFW2FewIDAQAB\n" |
| 94 | + "AoGAGUTSBsk6X03fcr588TundD9uNr/2V1002Ufj1msdnKPJ8FXIiy+8QVWt/2Cw\n" |
| 95 | + "RQi2J3VhkAYrlUDex2rr8Qas3E9uuwKgg/MZ4EsJbnKKgkd7uBZfmZ2ogcNJ82u7\n" |
| 96 | + "teVijFpdsVLDa9aczEppt5sZzyTaBrovrRb+AIRDpMw3I0ECQQD3JkWeQUA9Is1V\n" |
| 97 | + "z0X/ly/kaQKQLlrwYNdiKF0qOpyTLAguI7asAS72Zj7fThk5bHLM+mmgYwkicIIb\n" |
| 98 | + "67J32GQbAkEA8fkXqEnwMFYSkRmT9M/qUkwWUsMW12/AoZFI5gwKNDHZYxytGGLw\n" |
| 99 | + "mC//0qKnyeUG00vz06vLApe4/Sq4ODe6IQJBALEGastF9ZtUuDsEciD2y8kRJlLb\n" |
| 100 | + "wSt4Ug3u13yN6uTHnzxdPFTLrDW1WsdcC1lEQp5rpwjIpxxR9f/FvVl2V40CQHOY\n" |
| 101 | + "F6EhkUjGFaCTo4b0PHCMQK3Q3PyWOmP0z+p2HfnJRpx+eoKH4YASjhfF9HoSmywd\n" |
| 102 | + "wKGCFD1s1ca7vb29gYECQH86GmYZsDoLNWurEVJbkmCr7X1+xwim6umdrNKR27P7\n" |
| 103 | + "F1y0Sa3YY+LiiRb+IRSWE/onlP+28LIzWGF4lcTfDMc=\n" |
| 104 | + "-----END RSA PRIVATE KEY-----"; |
| 105 | |
| 106 | final byte[] der_public = new byte[] { |
| 107 | (byte) 0x30, (byte) 0x81, (byte) 0x9F, (byte) 0x30, (byte) 0x0D, (byte) 0x06, |
| 108 | (byte) 0x09, (byte) 0x2A, (byte) 0x86, (byte) 0x48, (byte) 0x86, (byte) 0xF7, |
| 109 | (byte) 0x0D, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x05, (byte) 0x00, |
| 110 | (byte) 0x03, (byte) 0x81, (byte) 0x8D, (byte) 0x00, (byte) 0x30, (byte) 0x81, |
| 111 | (byte) 0x89, (byte) 0x02, (byte) 0x81, (byte) 0x81, (byte) 0x00, (byte) 0xE9, |
| 112 | (byte) 0x9B, (byte) 0x82, (byte) 0x9A, (byte) 0x9B, (byte) 0x1B, (byte) 0xA5, |
| 113 | (byte) 0x26, (byte) 0x7C, (byte) 0x9C, (byte) 0x13, (byte) 0x33, (byte) 0x4E, |
| 114 | (byte) 0x34, (byte) 0x63, (byte) 0x3B, (byte) 0xA7, (byte) 0x40, (byte) 0xAF, |
| 115 | (byte) 0x01, (byte) 0xAA, (byte) 0x19, (byte) 0xC4, (byte) 0x91, (byte) 0x1D, |
| 116 | (byte) 0xE4, (byte) 0x3B, (byte) 0xE2, (byte) 0xA3, (byte) 0x96, (byte) 0xFA, |
| 117 | (byte) 0x05, (byte) 0x13, (byte) 0x9D, (byte) 0x0A, (byte) 0xD4, (byte) 0x4D, |
| 118 | (byte) 0x94, (byte) 0x4B, (byte) 0x01, (byte) 0xFB, (byte) 0xDB, (byte) 0xED, |
| 119 | (byte) 0x07, (byte) 0x9B, (byte) 0x61, (byte) 0x93, (byte) 0x20, (byte) 0xD5, |
| 120 | (byte) 0x0B, (byte) 0xB3, (byte) 0x7E, (byte) 0x21, (byte) 0x6D, (byte) 0x00, |
| 121 | (byte) 0x8E, (byte) 0xDC, (byte) 0x83, (byte) 0x13, (byte) 0xA8, (byte) 0x76, |
| 122 | (byte) 0x40, (byte) 0xFF, (byte) 0x80, (byte) 0x59, (byte) 0xAF, (byte) 0x9C, |
| 123 | (byte) 0xE1, (byte) 0xD8, (byte) 0x74, (byte) 0x44, (byte) 0xCD, (byte) 0xAE, |
| 124 | (byte) 0x35, (byte) 0x55, (byte) 0xE4, (byte) 0x51, (byte) 0x63, (byte) 0xEB, |
| 125 | (byte) 0x03, (byte) 0xC0, (byte) 0xBE, (byte) 0xF8, (byte) 0x61, (byte) 0xEF, |
| 126 | (byte) 0x10, (byte) 0x39, (byte) 0x71, (byte) 0x67, (byte) 0x34, (byte) 0x46, |
| 127 | (byte) 0x89, (byte) 0x01, (byte) 0x0C, (byte) 0xBA, (byte) 0x2A, (byte) 0x69, |
| 128 | (byte) 0x61, (byte) 0xF2, (byte) 0x32, (byte) 0x05, (byte) 0x59, (byte) 0x0E, |
| 129 | (byte) 0xFB, (byte) 0x8F, (byte) 0x86, (byte) 0x46, (byte) 0xF9, (byte) 0xE4, |
| 130 | (byte) 0x1B, (byte) 0x87, (byte) 0x4A, (byte) 0x8F, (byte) 0x3C, (byte) 0x6B, |
| 131 | (byte) 0x41, (byte) 0x83, (byte) 0xEA, (byte) 0x29, (byte) 0x42, (byte) 0xB7, |
| 132 | (byte) 0x0B, (byte) 0x83, (byte) 0xE0, (byte) 0x15, (byte) 0x6D, (byte) 0x85, |
| 133 | (byte) 0x7B, (byte) 0x02, (byte) 0x03, (byte) 0x01, (byte) 0x00, (byte) 0x01 |
| 134 | }; |
| 135 | |
| 136 | // We only need to test this on the OpenSSL provider. |
| 137 | Provider p = Security.getProvider(OpenSSLProvider.PROVIDER_NAME); |
| 138 | |
| 139 | /* ENGINE-based private key */ |
| 140 | NativeCryptoTest.loadTestEngine(); |
| 141 | OpenSSLEngine engine = OpenSSLEngine.getInstance(NativeCryptoTest.TEST_ENGINE_ID); |
| 142 | PrivateKey privKey = engine.getPrivateKeyById(pem_private); |
| 143 | assertTrue(privKey instanceof RSAPrivateKey); |
| 144 | |
| 145 | /* Non-ENGINE-based public key */ |
| 146 | KeyFactory kf = KeyFactory.getInstance("RSA", p); |
| 147 | PublicKey pubKey = kf.generatePublic(new X509EncodedKeySpec(der_public)); |
| 148 | |
| 149 | KeyPair kp = new KeyPair(pubKey, privKey); |
| 150 | |
| 151 | Set<Provider.Service> services = p.getServices(); |
| 152 | for (Provider.Service service : services) { |
| 153 | if ("Signature".equals(service.getType()) && service.getAlgorithm().contains("RSA")) { |
| 154 | Signature sig1 = Signature.getInstance(service.getAlgorithm(), p); |
| 155 | test_Signature(sig1, kp); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | } |
| 160 | |
| 161 | private final Map<String, KeyPair> keypairAlgorithmToInstance |
| 162 | = new HashMap<String, KeyPair>(); |
| 163 | |
| 164 | private KeyPair keyPair(String sigAlgorithm, String providerName) throws Exception { |
| 165 | if (sigAlgorithm.endsWith("Encryption")) { |
| 166 | sigAlgorithm = sigAlgorithm.substring(0, sigAlgorithm.length()-"Encryption".length()); |
| 167 | } |
| 168 | |
| 169 | String kpAlgorithm; |
| 170 | // note ECDSA must be before DSA |
| 171 | if (sigAlgorithm.endsWith("ECDSA")) { |
| 172 | kpAlgorithm = "EC"; |
| 173 | } else if (sigAlgorithm.endsWith("DSA")) { |
| 174 | kpAlgorithm = "DSA"; |
| 175 | } else if (sigAlgorithm.endsWith("RSA")) { |
| 176 | kpAlgorithm = "RSA"; |
| 177 | } else { |
| 178 | throw new Exception("Unknown KeyPair algorithm for Signature algorithm " |
| 179 | + sigAlgorithm); |
| 180 | } |
| 181 | |
| 182 | KeyPair kp = keypairAlgorithmToInstance.get(kpAlgorithm); |
| 183 | if (kp == null) { |
| 184 | kp = KeyPairGenerator.getInstance(kpAlgorithm).generateKeyPair(); |
| 185 | keypairAlgorithmToInstance.put(sigAlgorithm, kp); |
| 186 | } |
| 187 | return kp; |
| 188 | } |
| 189 | |
| 190 | private void test_Signature(Signature sig, KeyPair keyPair) throws Exception { |
| 191 | sig.initSign(keyPair.getPrivate()); |
| 192 | sig.update(DATA); |
| 193 | byte[] signature = sig.sign(); |
| 194 | assertNotNull(sig.getAlgorithm(), signature); |
| 195 | assertTrue(sig.getAlgorithm(), signature.length > 0); |
| 196 | |
| 197 | sig.initVerify(keyPair.getPublic()); |
| 198 | sig.update(DATA); |
| 199 | assertTrue(sig.getAlgorithm(), sig.verify(signature)); |
| 200 | |
| 201 | // After verify, should be reusable as if we are after initVerify |
| 202 | sig.update(DATA); |
| 203 | assertTrue(sig.getAlgorithm(), sig.verify(signature)); |
| 204 | |
| 205 | /* |
| 206 | * The RI appears to clear out the input data in RawDSA while calling |
| 207 | * verify a second time. |
| 208 | */ |
| 209 | if (StandardNames.IS_RI && "NONEwithDSA".equalsIgnoreCase(sig.getAlgorithm())) { |
| 210 | try { |
| 211 | sig.verify(signature); |
| 212 | fail("Expected RI to have a NONEwithDSA bug"); |
| 213 | } catch (SignatureException bug) { |
| 214 | } |
| 215 | } else { |
| 216 | // Calling Signature.verify a second time should not throw |
| 217 | // http://code.google.com/p/android/issues/detail?id=34933 |
| 218 | sig.verify(signature); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | private static final byte[] PK_BYTES = hexToBytes( |
| 223 | "30819f300d06092a864886f70d010101050003818d0030818902818100cd769d178f61475fce3001" |
| 224 | + "2604218320c77a427121d3b41dd76756c8fc0c428cd15cb754adc85466f47547b1c85623d9c17fc6" |
| 225 | + "4f202fca21099caf99460c824ad657caa8c2db34996838d32623c4f23c8b6a4e6698603901262619" |
| 226 | + "4840e0896b1a6ec4f6652484aad04569bb6a885b822a10d700224359c632dc7324520cbb3d020301" |
| 227 | + "0001"); |
| 228 | private static final byte[] CONTENT = hexToBytes( |
| 229 | "f2fa9d73656e00fa01edc12e73656e2e7670632e6432004867268c46dd95030b93ce7260423e5c00" |
| 230 | + "fabd4d656d6265727300fa018dc12e73656e2e7670632e643100d7c258dc00fabd44657669636573" |
| 231 | + "00faa54b65797300fa02b5c12e4d2e4b009471968cc68835f8a68dde10f53d19693d480de767e5fb" |
| 232 | + "976f3562324006372300fabdfd04e1f51ef3aa00fa8d00000001a203e202859471968cc68835f8a6" |
| 233 | + "8dde10f53d19693d480de767e5fb976f356232400637230002bab504e1f51ef5810002c29d28463f" |
| 234 | + "0003da8d000001e201eaf2fa9d73656e00fa01edc12e73656e2e7670632e6432004867268c46dd95" |
| 235 | + "030b93ce7260423e5c00fabd4d656d6265727300fa018dc12e73656e2e7670632e643100d7c258dc" |
| 236 | + "00fabd4465766963657300faa54b65797300fa02b5c12e4d2e4b009471968cc68835f8a68dde10f5" |
| 237 | + "3d19693d480de767e5fb976f3562324006372300fabdfd04e1f51ef3aa000003e202859471968cc6" |
| 238 | + "8835f8a68dde10f53d19693d480de767e5fb976f3562324006372300000000019a0a9530819f300d" |
| 239 | + "06092a864886f70d010101050003818d0030818902818100cd769d178f61475fce30012604218320" |
| 240 | + "c77a427121d3b41dd76756c8fc0c428cd15cb754adc85466f47547b1c85623d9c17fc64f202fca21" |
| 241 | + "099caf99460c824ad657caa8c2db34996838d32623c4f23c8b6a4e66986039012626194840e0896b" |
| 242 | + "1a6ec4f6652484aad04569bb6a885b822a10d700224359c632dc7324520cbb3d020301000100"); |
| 243 | private static final byte[] SIGNATURE = hexToBytes( |
| 244 | "b4016456148cd2e9f580470aad63d19c1fee52b38c9dcb5b4d61a7ca369a7277497775d106d86394" |
| 245 | + "a69229184333b5a3e6261d5bcebdb02530ca9909f4d790199eae7c140f7db39dee2232191bdf0bfb" |
| 246 | + "34fdadc44326b9b3f3fa828652bab07f0362ac141c8c3784ebdec44e0b156a5e7bccdc81a56fe954" |
| 247 | + "56ac8c0e4ae12d97"); |
| 248 | |
| 249 | private static byte[] hexToBytes(String s) { |
| 250 | int len = s.length(); |
| 251 | byte[] data = new byte[len / 2]; |
| 252 | for (int i = 0; i < len; i += 2) { |
| 253 | data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) |
| 254 | + Character.digit(s.charAt(i+1), 16)); |
| 255 | } |
| 256 | return data; |
| 257 | } |
| 258 | |
| 259 | // http://code.google.com/p/android/issues/detail?id=18566 |
| 260 | // http://b/5038554 |
| 261 | public void test18566() throws Exception { |
| 262 | X509EncodedKeySpec keySpec = new X509EncodedKeySpec(PK_BYTES); |
| 263 | KeyFactory keyFactory = KeyFactory.getInstance("RSA"); |
| 264 | PublicKey pk = keyFactory.generatePublic(keySpec); |
| 265 | |
| 266 | Signature sig = Signature.getInstance("SHA256withRSA"); |
| 267 | sig.initVerify(pk); |
| 268 | sig.update(CONTENT); |
| 269 | assertTrue(sig.verify(SIGNATURE)); |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Test vectors generated with this private key: |
| 274 | * |
| 275 | * -----BEGIN RSA PRIVATE KEY----- |
| 276 | * MIIEpAIBAAKCAQEA4Ec+irjyKE/rnnQv+XSPoRjtmGM8kvUq63ouvg075gMpvnZq |
| 277 | * 0Q62pRXQ0s/ZvqeTDwwwZTeJn3lYzT6FsB+IGFJNMSWEqUslHjYltUFB7b/uGYgI |
| 278 | * 4buX/Hy0m56qr2jpyY19DtxTu8D6ADQ1bWMF+7zDxwAUBThqu8hzyw8+90JfPTPf |
| 279 | * ezFa4DbSoLZq/UdQOxab8247UWJRW3Ff2oPeryxYrrmr+zCXw8yd2dvl7ylsF2E5 |
| 280 | * Ao6KZx5jBW1F9AGI0sQTNJCEXeUsJTTpxrJHjAe9rpKII7YtBmx3cPn2Pz26JH9T |
| 281 | * CER0e+eqqF2FO4vSRKzsPePImrRkU6tNJMOsaQIDAQABAoIBADd4R3al8XaY9ayW |
| 282 | * DfuDobZ1ZOZIvQWXz4q4CHGG8macJ6nsvdSA8Bl6gNBzCebGqW+SUzHlf4tKxvTU |
| 283 | * XtpFojJpwJ/EKMB6Tm7fc4oV3sl/q9Lyu0ehTyDqcvz+TDbgGtp3vRN82NTaELsW |
| 284 | * LpSkZilx8XX5hfoYjwVsuX7igW9Dq503R2Ekhs2owWGWwwgYqZXshdOEZ3kSZ7O/ |
| 285 | * IfJzcQppJYYldoQcW2cSwS1L0govMpmtt8E12l6VFavadufK8qO+gFUdBzt4vxFi |
| 286 | * xIrSt/R0OgI47k0lL31efmUzzK5kzLOTYAdaL9HgNOw65c6cQIzL8OJeQRQCFoez |
| 287 | * 3UdUroECgYEA9UGIS8Nzeyki1BGe9F4t7izUy7dfRVBaFXqlAJ+Zxzot8HJKxGAk |
| 288 | * MGMy6omBd2NFRl3G3x4KbxQK/ztzluaomUrF2qloc0cv43dJ0U6z4HXmKdvrNYMz |
| 289 | * im82SdCiZUp6Qv2atr+krE1IHTkLsimwZL3DEcwb4bYxidp8QM3s8rECgYEA6hp0 |
| 290 | * LduIHO23KIyH442GjdekCdFaQ/RF1Td6C1cx3b/KLa8oqOE81cCvzsM0fXSjniNa |
| 291 | * PNljPydN4rlPkt9DgzkR2enxz1jyfeLgj/RZZMcg0+whOdx8r8kSlTzeyy81Wi4s |
| 292 | * NaUPrXVMs7IxZkJLo7bjESoriYw4xcFe2yOGkzkCgYBRgo8exv2ZYCmQG68dfjN7 |
| 293 | * pfCvJ+mE6tiVrOYr199O5FoiQInyzBUa880XP84EdLywTzhqLNzA4ANrokGfVFeS |
| 294 | * YtRxAL6TGYSj76Bb7PFBV03AebOpXEqD5sQ/MhTW3zLVEt4ZgIXlMeYWuD/X3Z0f |
| 295 | * TiYHwzM9B8VdEH0dOJNYcQKBgQDbT7UPUN6O21P/NMgJMYigUShn2izKBIl3WeWH |
| 296 | * wkQBDa+GZNWegIPRbBZHiTAfZ6nweAYNg0oq29NnV1toqKhCwrAqibPzH8zsiiL+ |
| 297 | * OVeVxcbHQitOXXSh6ajzDndZufwtY5wfFWc+hOk6XvFQb0MVODw41Fy9GxQEj0ch |
| 298 | * 3IIyYQKBgQDYEUWTr0FfthLb8ZI3ENVNB0hiBadqO0MZSWjA3/HxHvD2GkozfV/T |
| 299 | * dBu8lkDkR7i2tsR8OsEgQ1fTsMVbqShr2nP2KSlvX6kUbYl2NX08dR51FIaWpAt0 |
| 300 | * aFyCzjCQLWOdck/yTV4ulAfuNO3tLjtN9lqpvP623yjQe6aQPxZXaA== |
| 301 | * -----END RSA PRIVATE KEY----- |
| 302 | * |
| 303 | */ |
| 304 | |
| 305 | private static final BigInteger RSA_2048_modulus = new BigInteger(new byte[] { |
| 306 | (byte) 0x00, (byte) 0xe0, (byte) 0x47, (byte) 0x3e, (byte) 0x8a, (byte) 0xb8, (byte) 0xf2, (byte) 0x28, |
| 307 | (byte) 0x4f, (byte) 0xeb, (byte) 0x9e, (byte) 0x74, (byte) 0x2f, (byte) 0xf9, (byte) 0x74, (byte) 0x8f, |
| 308 | (byte) 0xa1, (byte) 0x18, (byte) 0xed, (byte) 0x98, (byte) 0x63, (byte) 0x3c, (byte) 0x92, (byte) 0xf5, |
| 309 | (byte) 0x2a, (byte) 0xeb, (byte) 0x7a, (byte) 0x2e, (byte) 0xbe, (byte) 0x0d, (byte) 0x3b, (byte) 0xe6, |
| 310 | (byte) 0x03, (byte) 0x29, (byte) 0xbe, (byte) 0x76, (byte) 0x6a, (byte) 0xd1, (byte) 0x0e, (byte) 0xb6, |
| 311 | (byte) 0xa5, (byte) 0x15, (byte) 0xd0, (byte) 0xd2, (byte) 0xcf, (byte) 0xd9, (byte) 0xbe, (byte) 0xa7, |
| 312 | (byte) 0x93, (byte) 0x0f, (byte) 0x0c, (byte) 0x30, (byte) 0x65, (byte) 0x37, (byte) 0x89, (byte) 0x9f, |
| 313 | (byte) 0x79, (byte) 0x58, (byte) 0xcd, (byte) 0x3e, (byte) 0x85, (byte) 0xb0, (byte) 0x1f, (byte) 0x88, |
| 314 | (byte) 0x18, (byte) 0x52, (byte) 0x4d, (byte) 0x31, (byte) 0x25, (byte) 0x84, (byte) 0xa9, (byte) 0x4b, |
| 315 | (byte) 0x25, (byte) 0x1e, (byte) 0x36, (byte) 0x25, (byte) 0xb5, (byte) 0x41, (byte) 0x41, (byte) 0xed, |
| 316 | (byte) 0xbf, (byte) 0xee, (byte) 0x19, (byte) 0x88, (byte) 0x08, (byte) 0xe1, (byte) 0xbb, (byte) 0x97, |
| 317 | (byte) 0xfc, (byte) 0x7c, (byte) 0xb4, (byte) 0x9b, (byte) 0x9e, (byte) 0xaa, (byte) 0xaf, (byte) 0x68, |
| 318 | (byte) 0xe9, (byte) 0xc9, (byte) 0x8d, (byte) 0x7d, (byte) 0x0e, (byte) 0xdc, (byte) 0x53, (byte) 0xbb, |
| 319 | (byte) 0xc0, (byte) 0xfa, (byte) 0x00, (byte) 0x34, (byte) 0x35, (byte) 0x6d, (byte) 0x63, (byte) 0x05, |
| 320 | (byte) 0xfb, (byte) 0xbc, (byte) 0xc3, (byte) 0xc7, (byte) 0x00, (byte) 0x14, (byte) 0x05, (byte) 0x38, |
| 321 | (byte) 0x6a, (byte) 0xbb, (byte) 0xc8, (byte) 0x73, (byte) 0xcb, (byte) 0x0f, (byte) 0x3e, (byte) 0xf7, |
| 322 | (byte) 0x42, (byte) 0x5f, (byte) 0x3d, (byte) 0x33, (byte) 0xdf, (byte) 0x7b, (byte) 0x31, (byte) 0x5a, |
| 323 | (byte) 0xe0, (byte) 0x36, (byte) 0xd2, (byte) 0xa0, (byte) 0xb6, (byte) 0x6a, (byte) 0xfd, (byte) 0x47, |
| 324 | (byte) 0x50, (byte) 0x3b, (byte) 0x16, (byte) 0x9b, (byte) 0xf3, (byte) 0x6e, (byte) 0x3b, (byte) 0x51, |
| 325 | (byte) 0x62, (byte) 0x51, (byte) 0x5b, (byte) 0x71, (byte) 0x5f, (byte) 0xda, (byte) 0x83, (byte) 0xde, |
| 326 | (byte) 0xaf, (byte) 0x2c, (byte) 0x58, (byte) 0xae, (byte) 0xb9, (byte) 0xab, (byte) 0xfb, (byte) 0x30, |
| 327 | (byte) 0x97, (byte) 0xc3, (byte) 0xcc, (byte) 0x9d, (byte) 0xd9, (byte) 0xdb, (byte) 0xe5, (byte) 0xef, |
| 328 | (byte) 0x29, (byte) 0x6c, (byte) 0x17, (byte) 0x61, (byte) 0x39, (byte) 0x02, (byte) 0x8e, (byte) 0x8a, |
| 329 | (byte) 0x67, (byte) 0x1e, (byte) 0x63, (byte) 0x05, (byte) 0x6d, (byte) 0x45, (byte) 0xf4, (byte) 0x01, |
| 330 | (byte) 0x88, (byte) 0xd2, (byte) 0xc4, (byte) 0x13, (byte) 0x34, (byte) 0x90, (byte) 0x84, (byte) 0x5d, |
| 331 | (byte) 0xe5, (byte) 0x2c, (byte) 0x25, (byte) 0x34, (byte) 0xe9, (byte) 0xc6, (byte) 0xb2, (byte) 0x47, |
| 332 | (byte) 0x8c, (byte) 0x07, (byte) 0xbd, (byte) 0xae, (byte) 0x92, (byte) 0x88, (byte) 0x23, (byte) 0xb6, |
| 333 | (byte) 0x2d, (byte) 0x06, (byte) 0x6c, (byte) 0x77, (byte) 0x70, (byte) 0xf9, (byte) 0xf6, (byte) 0x3f, |
| 334 | (byte) 0x3d, (byte) 0xba, (byte) 0x24, (byte) 0x7f, (byte) 0x53, (byte) 0x08, (byte) 0x44, (byte) 0x74, |
| 335 | (byte) 0x7b, (byte) 0xe7, (byte) 0xaa, (byte) 0xa8, (byte) 0x5d, (byte) 0x85, (byte) 0x3b, (byte) 0x8b, |
| 336 | (byte) 0xd2, (byte) 0x44, (byte) 0xac, (byte) 0xec, (byte) 0x3d, (byte) 0xe3, (byte) 0xc8, (byte) 0x9a, |
| 337 | (byte) 0xb4, (byte) 0x64, (byte) 0x53, (byte) 0xab, (byte) 0x4d, (byte) 0x24, (byte) 0xc3, (byte) 0xac, |
| 338 | (byte) 0x69, |
| 339 | }); |
| 340 | |
| 341 | private static final BigInteger RSA_2048_privateExponent = new BigInteger(new byte[] { |
| 342 | (byte) 0x37, (byte) 0x78, (byte) 0x47, (byte) 0x76, (byte) 0xa5, (byte) 0xf1, (byte) 0x76, (byte) 0x98, |
| 343 | (byte) 0xf5, (byte) 0xac, (byte) 0x96, (byte) 0x0d, (byte) 0xfb, (byte) 0x83, (byte) 0xa1, (byte) 0xb6, |
| 344 | (byte) 0x75, (byte) 0x64, (byte) 0xe6, (byte) 0x48, (byte) 0xbd, (byte) 0x05, (byte) 0x97, (byte) 0xcf, |
| 345 | (byte) 0x8a, (byte) 0xb8, (byte) 0x08, (byte) 0x71, (byte) 0x86, (byte) 0xf2, (byte) 0x66, (byte) 0x9c, |
| 346 | (byte) 0x27, (byte) 0xa9, (byte) 0xec, (byte) 0xbd, (byte) 0xd4, (byte) 0x80, (byte) 0xf0, (byte) 0x19, |
| 347 | (byte) 0x7a, (byte) 0x80, (byte) 0xd0, (byte) 0x73, (byte) 0x09, (byte) 0xe6, (byte) 0xc6, (byte) 0xa9, |
| 348 | (byte) 0x6f, (byte) 0x92, (byte) 0x53, (byte) 0x31, (byte) 0xe5, (byte) 0x7f, (byte) 0x8b, (byte) 0x4a, |
| 349 | (byte) 0xc6, (byte) 0xf4, (byte) 0xd4, (byte) 0x5e, (byte) 0xda, (byte) 0x45, (byte) 0xa2, (byte) 0x32, |
| 350 | (byte) 0x69, (byte) 0xc0, (byte) 0x9f, (byte) 0xc4, (byte) 0x28, (byte) 0xc0, (byte) 0x7a, (byte) 0x4e, |
| 351 | (byte) 0x6e, (byte) 0xdf, (byte) 0x73, (byte) 0x8a, (byte) 0x15, (byte) 0xde, (byte) 0xc9, (byte) 0x7f, |
| 352 | (byte) 0xab, (byte) 0xd2, (byte) 0xf2, (byte) 0xbb, (byte) 0x47, (byte) 0xa1, (byte) 0x4f, (byte) 0x20, |
| 353 | (byte) 0xea, (byte) 0x72, (byte) 0xfc, (byte) 0xfe, (byte) 0x4c, (byte) 0x36, (byte) 0xe0, (byte) 0x1a, |
| 354 | (byte) 0xda, (byte) 0x77, (byte) 0xbd, (byte) 0x13, (byte) 0x7c, (byte) 0xd8, (byte) 0xd4, (byte) 0xda, |
| 355 | (byte) 0x10, (byte) 0xbb, (byte) 0x16, (byte) 0x2e, (byte) 0x94, (byte) 0xa4, (byte) 0x66, (byte) 0x29, |
| 356 | (byte) 0x71, (byte) 0xf1, (byte) 0x75, (byte) 0xf9, (byte) 0x85, (byte) 0xfa, (byte) 0x18, (byte) 0x8f, |
| 357 | (byte) 0x05, (byte) 0x6c, (byte) 0xb9, (byte) 0x7e, (byte) 0xe2, (byte) 0x81, (byte) 0x6f, (byte) 0x43, |
| 358 | (byte) 0xab, (byte) 0x9d, (byte) 0x37, (byte) 0x47, (byte) 0x61, (byte) 0x24, (byte) 0x86, (byte) 0xcd, |
| 359 | (byte) 0xa8, (byte) 0xc1, (byte) 0x61, (byte) 0x96, (byte) 0xc3, (byte) 0x08, (byte) 0x18, (byte) 0xa9, |
| 360 | (byte) 0x95, (byte) 0xec, (byte) 0x85, (byte) 0xd3, (byte) 0x84, (byte) 0x67, (byte) 0x79, (byte) 0x12, |
| 361 | (byte) 0x67, (byte) 0xb3, (byte) 0xbf, (byte) 0x21, (byte) 0xf2, (byte) 0x73, (byte) 0x71, (byte) 0x0a, |
| 362 | (byte) 0x69, (byte) 0x25, (byte) 0x86, (byte) 0x25, (byte) 0x76, (byte) 0x84, (byte) 0x1c, (byte) 0x5b, |
| 363 | (byte) 0x67, (byte) 0x12, (byte) 0xc1, (byte) 0x2d, (byte) 0x4b, (byte) 0xd2, (byte) 0x0a, (byte) 0x2f, |
| 364 | (byte) 0x32, (byte) 0x99, (byte) 0xad, (byte) 0xb7, (byte) 0xc1, (byte) 0x35, (byte) 0xda, (byte) 0x5e, |
| 365 | (byte) 0x95, (byte) 0x15, (byte) 0xab, (byte) 0xda, (byte) 0x76, (byte) 0xe7, (byte) 0xca, (byte) 0xf2, |
| 366 | (byte) 0xa3, (byte) 0xbe, (byte) 0x80, (byte) 0x55, (byte) 0x1d, (byte) 0x07, (byte) 0x3b, (byte) 0x78, |
| 367 | (byte) 0xbf, (byte) 0x11, (byte) 0x62, (byte) 0xc4, (byte) 0x8a, (byte) 0xd2, (byte) 0xb7, (byte) 0xf4, |
| 368 | (byte) 0x74, (byte) 0x3a, (byte) 0x02, (byte) 0x38, (byte) 0xee, (byte) 0x4d, (byte) 0x25, (byte) 0x2f, |
| 369 | (byte) 0x7d, (byte) 0x5e, (byte) 0x7e, (byte) 0x65, (byte) 0x33, (byte) 0xcc, (byte) 0xae, (byte) 0x64, |
| 370 | (byte) 0xcc, (byte) 0xb3, (byte) 0x93, (byte) 0x60, (byte) 0x07, (byte) 0x5a, (byte) 0x2f, (byte) 0xd1, |
| 371 | (byte) 0xe0, (byte) 0x34, (byte) 0xec, (byte) 0x3a, (byte) 0xe5, (byte) 0xce, (byte) 0x9c, (byte) 0x40, |
| 372 | (byte) 0x8c, (byte) 0xcb, (byte) 0xf0, (byte) 0xe2, (byte) 0x5e, (byte) 0x41, (byte) 0x14, (byte) 0x02, |
| 373 | (byte) 0x16, (byte) 0x87, (byte) 0xb3, (byte) 0xdd, (byte) 0x47, (byte) 0x54, (byte) 0xae, (byte) 0x81, |
| 374 | }); |
| 375 | |
| 376 | private static final BigInteger RSA_2048_publicExponent = new BigInteger(new byte[] { |
| 377 | (byte) 0x01, (byte) 0x00, (byte) 0x01, |
| 378 | }); |
| 379 | |
| 380 | private static final BigInteger RSA_2048_primeP = new BigInteger(new byte[] { |
| 381 | (byte) 0x00, (byte) 0xf5, (byte) 0x41, (byte) 0x88, (byte) 0x4b, (byte) 0xc3, (byte) 0x73, (byte) 0x7b, |
| 382 | (byte) 0x29, (byte) 0x22, (byte) 0xd4, (byte) 0x11, (byte) 0x9e, (byte) 0xf4, (byte) 0x5e, (byte) 0x2d, |
| 383 | (byte) 0xee, (byte) 0x2c, (byte) 0xd4, (byte) 0xcb, (byte) 0xb7, (byte) 0x5f, (byte) 0x45, (byte) 0x50, |
| 384 | (byte) 0x5a, (byte) 0x15, (byte) 0x7a, (byte) 0xa5, (byte) 0x00, (byte) 0x9f, (byte) 0x99, (byte) 0xc7, |
| 385 | (byte) 0x3a, (byte) 0x2d, (byte) 0xf0, (byte) 0x72, (byte) 0x4a, (byte) 0xc4, (byte) 0x60, (byte) 0x24, |
| 386 | (byte) 0x30, (byte) 0x63, (byte) 0x32, (byte) 0xea, (byte) 0x89, (byte) 0x81, (byte) 0x77, (byte) 0x63, |
| 387 | (byte) 0x45, (byte) 0x46, (byte) 0x5d, (byte) 0xc6, (byte) 0xdf, (byte) 0x1e, (byte) 0x0a, (byte) 0x6f, |
| 388 | (byte) 0x14, (byte) 0x0a, (byte) 0xff, (byte) 0x3b, (byte) 0x73, (byte) 0x96, (byte) 0xe6, (byte) 0xa8, |
| 389 | (byte) 0x99, (byte) 0x4a, (byte) 0xc5, (byte) 0xda, (byte) 0xa9, (byte) 0x68, (byte) 0x73, (byte) 0x47, |
| 390 | (byte) 0x2f, (byte) 0xe3, (byte) 0x77, (byte) 0x49, (byte) 0xd1, (byte) 0x4e, (byte) 0xb3, (byte) 0xe0, |
| 391 | (byte) 0x75, (byte) 0xe6, (byte) 0x29, (byte) 0xdb, (byte) 0xeb, (byte) 0x35, (byte) 0x83, (byte) 0x33, |
| 392 | (byte) 0x8a, (byte) 0x6f, (byte) 0x36, (byte) 0x49, (byte) 0xd0, (byte) 0xa2, (byte) 0x65, (byte) 0x4a, |
| 393 | (byte) 0x7a, (byte) 0x42, (byte) 0xfd, (byte) 0x9a, (byte) 0xb6, (byte) 0xbf, (byte) 0xa4, (byte) 0xac, |
| 394 | (byte) 0x4d, (byte) 0x48, (byte) 0x1d, (byte) 0x39, (byte) 0x0b, (byte) 0xb2, (byte) 0x29, (byte) 0xb0, |
| 395 | (byte) 0x64, (byte) 0xbd, (byte) 0xc3, (byte) 0x11, (byte) 0xcc, (byte) 0x1b, (byte) 0xe1, (byte) 0xb6, |
| 396 | (byte) 0x31, (byte) 0x89, (byte) 0xda, (byte) 0x7c, (byte) 0x40, (byte) 0xcd, (byte) 0xec, (byte) 0xf2, |
| 397 | (byte) 0xb1, |
| 398 | }); |
| 399 | |
| 400 | private static final BigInteger RSA_2048_primeQ = new BigInteger(new byte[] { |
| 401 | (byte) 0x00, (byte) 0xea, (byte) 0x1a, (byte) 0x74, (byte) 0x2d, (byte) 0xdb, (byte) 0x88, (byte) 0x1c, |
| 402 | (byte) 0xed, (byte) 0xb7, (byte) 0x28, (byte) 0x8c, (byte) 0x87, (byte) 0xe3, (byte) 0x8d, (byte) 0x86, |
| 403 | (byte) 0x8d, (byte) 0xd7, (byte) 0xa4, (byte) 0x09, (byte) 0xd1, (byte) 0x5a, (byte) 0x43, (byte) 0xf4, |
| 404 | (byte) 0x45, (byte) 0xd5, (byte) 0x37, (byte) 0x7a, (byte) 0x0b, (byte) 0x57, (byte) 0x31, (byte) 0xdd, |
| 405 | (byte) 0xbf, (byte) 0xca, (byte) 0x2d, (byte) 0xaf, (byte) 0x28, (byte) 0xa8, (byte) 0xe1, (byte) 0x3c, |
| 406 | (byte) 0xd5, (byte) 0xc0, (byte) 0xaf, (byte) 0xce, (byte) 0xc3, (byte) 0x34, (byte) 0x7d, (byte) 0x74, |
| 407 | (byte) 0xa3, (byte) 0x9e, (byte) 0x23, (byte) 0x5a, (byte) 0x3c, (byte) 0xd9, (byte) 0x63, (byte) 0x3f, |
| 408 | (byte) 0x27, (byte) 0x4d, (byte) 0xe2, (byte) 0xb9, (byte) 0x4f, (byte) 0x92, (byte) 0xdf, (byte) 0x43, |
| 409 | (byte) 0x83, (byte) 0x39, (byte) 0x11, (byte) 0xd9, (byte) 0xe9, (byte) 0xf1, (byte) 0xcf, (byte) 0x58, |
| 410 | (byte) 0xf2, (byte) 0x7d, (byte) 0xe2, (byte) 0xe0, (byte) 0x8f, (byte) 0xf4, (byte) 0x59, (byte) 0x64, |
| 411 | (byte) 0xc7, (byte) 0x20, (byte) 0xd3, (byte) 0xec, (byte) 0x21, (byte) 0x39, (byte) 0xdc, (byte) 0x7c, |
| 412 | (byte) 0xaf, (byte) 0xc9, (byte) 0x12, (byte) 0x95, (byte) 0x3c, (byte) 0xde, (byte) 0xcb, (byte) 0x2f, |
| 413 | (byte) 0x35, (byte) 0x5a, (byte) 0x2e, (byte) 0x2c, (byte) 0x35, (byte) 0xa5, (byte) 0x0f, (byte) 0xad, |
| 414 | (byte) 0x75, (byte) 0x4c, (byte) 0xb3, (byte) 0xb2, (byte) 0x31, (byte) 0x66, (byte) 0x42, (byte) 0x4b, |
| 415 | (byte) 0xa3, (byte) 0xb6, (byte) 0xe3, (byte) 0x11, (byte) 0x2a, (byte) 0x2b, (byte) 0x89, (byte) 0x8c, |
| 416 | (byte) 0x38, (byte) 0xc5, (byte) 0xc1, (byte) 0x5e, (byte) 0xdb, (byte) 0x23, (byte) 0x86, (byte) 0x93, |
| 417 | (byte) 0x39, |
| 418 | }); |
| 419 | |
| 420 | /* Test data is: "Android.\n" */ |
| 421 | private static final byte[] Vector1Data = new byte[] { |
| 422 | (byte) 0x41, (byte) 0x6e, (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x2e, |
| 423 | (byte) 0x0a, |
| 424 | }; |
| 425 | |
| 426 | private static final byte[] SHA1withRSA_Vector1Signature = { |
| 427 | (byte) 0x6d, (byte) 0x5b, (byte) 0xff, (byte) 0x68, (byte) 0xda, (byte) 0x18, (byte) 0x98, (byte) 0x72, |
| 428 | (byte) 0x5c, (byte) 0x1f, (byte) 0x46, (byte) 0x51, (byte) 0x77, (byte) 0x15, (byte) 0x11, (byte) 0xcb, |
| 429 | (byte) 0xe0, (byte) 0xb9, (byte) 0x3b, (byte) 0x7d, (byte) 0xf5, (byte) 0x96, (byte) 0x98, (byte) 0x24, |
| 430 | (byte) 0x85, (byte) 0x9d, (byte) 0x3e, (byte) 0xed, (byte) 0x9b, (byte) 0xb2, (byte) 0x8a, (byte) 0x91, |
| 431 | (byte) 0xfb, (byte) 0xf6, (byte) 0x85, (byte) 0x64, (byte) 0x74, (byte) 0x18, (byte) 0xb5, (byte) 0x1c, |
| 432 | (byte) 0xb3, (byte) 0x8d, (byte) 0x99, (byte) 0x0d, (byte) 0xdf, (byte) 0xaa, (byte) 0xa6, (byte) 0xa1, |
| 433 | (byte) 0xc3, (byte) 0xb6, (byte) 0x25, (byte) 0xb3, (byte) 0x06, (byte) 0xe0, (byte) 0xef, (byte) 0x28, |
| 434 | (byte) 0xb0, (byte) 0x4d, (byte) 0x50, (byte) 0xc7, (byte) 0x75, (byte) 0x39, (byte) 0xb9, (byte) 0x2c, |
| 435 | (byte) 0x47, (byte) 0xb5, (byte) 0xe2, (byte) 0x96, (byte) 0xf8, (byte) 0xf6, (byte) 0xcb, (byte) 0xa0, |
| 436 | (byte) 0x58, (byte) 0xc9, (byte) 0x3e, (byte) 0xd5, (byte) 0xfc, (byte) 0x26, (byte) 0xd9, (byte) 0x55, |
| 437 | (byte) 0x73, (byte) 0x39, (byte) 0x75, (byte) 0xb3, (byte) 0xb0, (byte) 0x0a, (byte) 0x5f, (byte) 0x5e, |
| 438 | (byte) 0x3b, (byte) 0x4a, (byte) 0x2e, (byte) 0xb1, (byte) 0x0e, (byte) 0x7d, (byte) 0xe5, (byte) 0xcc, |
| 439 | (byte) 0x04, (byte) 0x2c, (byte) 0xd1, (byte) 0x0a, (byte) 0x32, (byte) 0xaa, (byte) 0xd9, (byte) 0x8d, |
| 440 | (byte) 0x1f, (byte) 0xcb, (byte) 0xe3, (byte) 0x7f, (byte) 0x63, (byte) 0x12, (byte) 0xb1, (byte) 0x98, |
| 441 | (byte) 0x46, (byte) 0x46, (byte) 0x07, (byte) 0xd9, (byte) 0x49, (byte) 0xd2, (byte) 0xbf, (byte) 0xb5, |
| 442 | (byte) 0xbc, (byte) 0xbb, (byte) 0xfd, (byte) 0x1c, (byte) 0xd7, (byte) 0x11, (byte) 0x94, (byte) 0xaa, |
| 443 | (byte) 0x5f, (byte) 0x7b, (byte) 0xb2, (byte) 0x0c, (byte) 0x5d, (byte) 0x94, (byte) 0x53, (byte) 0x5e, |
| 444 | (byte) 0x81, (byte) 0x5c, (byte) 0xbb, (byte) 0x1d, (byte) 0x4f, (byte) 0x30, (byte) 0xcd, (byte) 0xf8, |
| 445 | (byte) 0xd7, (byte) 0xa5, (byte) 0xfa, (byte) 0x5e, (byte) 0xe0, (byte) 0x19, (byte) 0x3f, (byte) 0xa4, |
| 446 | (byte) 0xaa, (byte) 0x56, (byte) 0x4e, (byte) 0xec, (byte) 0xeb, (byte) 0xee, (byte) 0xa2, (byte) 0x6c, |
| 447 | (byte) 0xc9, (byte) 0x4f, (byte) 0xc2, (byte) 0xcc, (byte) 0x2a, (byte) 0xbc, (byte) 0x5b, (byte) 0x09, |
| 448 | (byte) 0x10, (byte) 0x73, (byte) 0x61, (byte) 0x0c, (byte) 0x04, (byte) 0xb6, (byte) 0xb7, (byte) 0x2c, |
| 449 | (byte) 0x37, (byte) 0xd2, (byte) 0xca, (byte) 0x2d, (byte) 0x54, (byte) 0xf2, (byte) 0xf7, (byte) 0x77, |
| 450 | (byte) 0xe1, (byte) 0xba, (byte) 0x9f, (byte) 0x29, (byte) 0x07, (byte) 0xa2, (byte) 0x74, (byte) 0xc6, |
| 451 | (byte) 0xe9, (byte) 0x1e, (byte) 0xde, (byte) 0xd7, (byte) 0x9c, (byte) 0x4b, (byte) 0xb7, (byte) 0x66, |
| 452 | (byte) 0x52, (byte) 0xe8, (byte) 0xac, (byte) 0xf6, (byte) 0x76, (byte) 0xab, (byte) 0x16, (byte) 0x82, |
| 453 | (byte) 0x96, (byte) 0x87, (byte) 0x40, (byte) 0x0f, (byte) 0xad, (byte) 0x2d, (byte) 0x46, (byte) 0xa6, |
| 454 | (byte) 0x28, (byte) 0x04, (byte) 0x13, (byte) 0xc2, (byte) 0xce, (byte) 0x50, (byte) 0x56, (byte) 0x6d, |
| 455 | (byte) 0xbe, (byte) 0x0c, (byte) 0x91, (byte) 0xd0, (byte) 0x8e, (byte) 0x80, (byte) 0x9e, (byte) 0x91, |
| 456 | (byte) 0x8f, (byte) 0x62, (byte) 0xb3, (byte) 0x57, (byte) 0xd6, (byte) 0xae, (byte) 0x53, (byte) 0x91, |
| 457 | (byte) 0x83, (byte) 0xe9, (byte) 0x38, (byte) 0x77, (byte) 0x8f, (byte) 0x20, (byte) 0xdd, (byte) 0x13, |
| 458 | (byte) 0x7d, (byte) 0x15, (byte) 0x44, (byte) 0x7e, (byte) 0xb5, (byte) 0x00, (byte) 0xd6, (byte) 0x45, |
| 459 | }; |
| 460 | |
| 461 | private static final byte[] Vector2Data = new byte[] { |
| 462 | (byte) 0x54, (byte) 0x68, (byte) 0x69, (byte) 0x73, (byte) 0x20, (byte) 0x69, (byte) 0x73, (byte) 0x20, |
| 463 | (byte) 0x61, (byte) 0x20, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x65, (byte) 0x64, |
| 464 | (byte) 0x20, (byte) 0x6d, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x61, (byte) 0x67, (byte) 0x65, |
| 465 | (byte) 0x20, (byte) 0x66, (byte) 0x72, (byte) 0x6f, (byte) 0x6d, (byte) 0x20, (byte) 0x4b, (byte) 0x65, |
| 466 | (byte) 0x6e, (byte) 0x6e, (byte) 0x79, (byte) 0x20, (byte) 0x52, (byte) 0x6f, (byte) 0x6f, (byte) 0x74, |
| 467 | (byte) 0x2e, (byte) 0x0a, |
| 468 | }; |
| 469 | |
| 470 | private static final byte[] SHA1withRSA_Vector2Signature = new byte[] { |
| 471 | (byte) 0x2e, (byte) 0xa6, (byte) 0x33, (byte) 0xd1, (byte) 0x9d, (byte) 0xfc, (byte) 0x4e, (byte) 0x27, |
| 472 | (byte) 0xb3, (byte) 0xa8, (byte) 0x9a, (byte) 0xf2, (byte) 0x48, (byte) 0x62, (byte) 0x15, (byte) 0xa2, |
| 473 | (byte) 0xce, (byte) 0x5f, (byte) 0x2b, (byte) 0x0e, (byte) 0xc5, (byte) 0x26, (byte) 0xba, (byte) 0xd9, |
| 474 | (byte) 0x0f, (byte) 0x60, (byte) 0xeb, (byte) 0xf0, (byte) 0xd5, (byte) 0x5c, (byte) 0x6b, (byte) 0x23, |
| 475 | (byte) 0x11, (byte) 0x95, (byte) 0xa4, (byte) 0xbd, (byte) 0x11, (byte) 0x68, (byte) 0xe7, (byte) 0x3a, |
| 476 | (byte) 0x37, (byte) 0x3d, (byte) 0x79, (byte) 0xb8, (byte) 0x4f, (byte) 0xe9, (byte) 0xa1, (byte) 0x88, |
| 477 | (byte) 0xfb, (byte) 0xa9, (byte) 0x8b, (byte) 0x34, (byte) 0xa1, (byte) 0xe0, (byte) 0xca, (byte) 0x11, |
| 478 | (byte) 0xdd, (byte) 0xd0, (byte) 0x83, (byte) 0x7f, (byte) 0xc1, (byte) 0x0b, (byte) 0x16, (byte) 0x61, |
| 479 | (byte) 0xac, (byte) 0x09, (byte) 0xa2, (byte) 0xdd, (byte) 0x40, (byte) 0x5b, (byte) 0x8c, (byte) 0x7a, |
| 480 | (byte) 0xb2, (byte) 0xb4, (byte) 0x02, (byte) 0x7c, (byte) 0xd4, (byte) 0x9a, (byte) 0xe6, (byte) 0xa5, |
| 481 | (byte) 0x1a, (byte) 0x27, (byte) 0x77, (byte) 0x70, (byte) 0xe3, (byte) 0xe3, (byte) 0x71, (byte) 0xc7, |
| 482 | (byte) 0x59, (byte) 0xc7, (byte) 0x9f, (byte) 0xb8, (byte) 0xef, (byte) 0xe7, (byte) 0x15, (byte) 0x02, |
| 483 | (byte) 0x0d, (byte) 0x70, (byte) 0xdc, (byte) 0x2c, (byte) 0xe9, (byte) 0xf7, (byte) 0x63, (byte) 0x2a, |
| 484 | (byte) 0xb5, (byte) 0xee, (byte) 0x9f, (byte) 0x29, (byte) 0x56, (byte) 0x86, (byte) 0x99, (byte) 0xb3, |
| 485 | (byte) 0x0f, (byte) 0xe5, (byte) 0x1f, (byte) 0x76, (byte) 0x22, (byte) 0x3b, (byte) 0x7f, (byte) 0xa9, |
| 486 | (byte) 0x9e, (byte) 0xd4, (byte) 0xc4, (byte) 0x83, (byte) 0x5d, (byte) 0x57, (byte) 0xcc, (byte) 0x37, |
| 487 | (byte) 0xcb, (byte) 0x9a, (byte) 0x9e, (byte) 0x73, (byte) 0x44, (byte) 0x93, (byte) 0xb4, (byte) 0xf1, |
| 488 | (byte) 0x6b, (byte) 0x98, (byte) 0xa0, (byte) 0x57, (byte) 0xbb, (byte) 0x5e, (byte) 0x8f, (byte) 0x89, |
| 489 | (byte) 0x5b, (byte) 0x97, (byte) 0x26, (byte) 0xe4, (byte) 0xd0, (byte) 0x51, (byte) 0x0a, (byte) 0x5a, |
| 490 | (byte) 0xb7, (byte) 0x12, (byte) 0x1a, (byte) 0x6d, (byte) 0xb0, (byte) 0x79, (byte) 0x30, (byte) 0x51, |
| 491 | (byte) 0x83, (byte) 0x2e, (byte) 0xe2, (byte) 0x7a, (byte) 0x67, (byte) 0x66, (byte) 0xd3, (byte) 0x95, |
| 492 | (byte) 0xca, (byte) 0xfc, (byte) 0xcb, (byte) 0x92, (byte) 0x79, (byte) 0x32, (byte) 0x26, (byte) 0x86, |
| 493 | (byte) 0xe1, (byte) 0x0d, (byte) 0xd8, (byte) 0x19, (byte) 0xfa, (byte) 0x65, (byte) 0x37, (byte) 0xc9, |
| 494 | (byte) 0x4c, (byte) 0x2a, (byte) 0xe1, (byte) 0x42, (byte) 0xc7, (byte) 0xd4, (byte) 0xb7, (byte) 0xeb, |
| 495 | (byte) 0x1f, (byte) 0xc3, (byte) 0x53, (byte) 0x64, (byte) 0x6f, (byte) 0x2b, (byte) 0x78, (byte) 0x18, |
| 496 | (byte) 0x03, (byte) 0xda, (byte) 0x8d, (byte) 0x62, (byte) 0x24, (byte) 0x70, (byte) 0xab, (byte) 0xe6, |
| 497 | (byte) 0x16, (byte) 0x13, (byte) 0x24, (byte) 0x6b, (byte) 0x5f, (byte) 0xd3, (byte) 0xec, (byte) 0xc1, |
| 498 | (byte) 0x58, (byte) 0x64, (byte) 0xbd, (byte) 0x30, (byte) 0x98, (byte) 0x5e, (byte) 0x33, (byte) 0xce, |
| 499 | (byte) 0x87, (byte) 0x64, (byte) 0x14, (byte) 0x07, (byte) 0x85, (byte) 0x43, (byte) 0x3e, (byte) 0x9f, |
| 500 | (byte) 0x27, (byte) 0x9f, (byte) 0x63, (byte) 0x66, (byte) 0x9d, (byte) 0x26, (byte) 0x19, (byte) 0xc0, |
| 501 | (byte) 0x02, (byte) 0x08, (byte) 0x15, (byte) 0xcb, (byte) 0xb4, (byte) 0xaa, (byte) 0x4a, (byte) 0xc8, |
| 502 | (byte) 0xc0, (byte) 0x09, (byte) 0x15, (byte) 0x7d, (byte) 0x8a, (byte) 0x21, (byte) 0xbc, (byte) 0xa3, |
| 503 | }; |
| 504 | |
| 505 | private static final byte[] SHA256withRSA_Vector2Signature = new byte[] { |
| 506 | (byte) 0x18, (byte) 0x6e, (byte) 0x31, (byte) 0x1f, (byte) 0x1d, (byte) 0x44, (byte) 0x09, (byte) 0x3e, |
| 507 | (byte) 0xa0, (byte) 0xc4, (byte) 0x3d, (byte) 0xb4, (byte) 0x1b, (byte) 0xf2, (byte) 0xd8, (byte) 0xa4, |
| 508 | (byte) 0x59, (byte) 0xab, (byte) 0xb5, (byte) 0x37, (byte) 0x28, (byte) 0xb8, (byte) 0x94, (byte) 0x6b, |
| 509 | (byte) 0x6f, (byte) 0x13, (byte) 0x54, (byte) 0xff, (byte) 0xac, (byte) 0x15, (byte) 0x84, (byte) 0xd0, |
| 510 | (byte) 0xc9, (byte) 0x15, (byte) 0x5b, (byte) 0x69, (byte) 0x05, (byte) 0xf1, (byte) 0x44, (byte) 0xfd, |
| 511 | (byte) 0xde, (byte) 0xe8, (byte) 0xb4, (byte) 0x12, (byte) 0x59, (byte) 0x9e, (byte) 0x4c, (byte) 0x0b, |
| 512 | (byte) 0xd5, (byte) 0x49, (byte) 0x33, (byte) 0x28, (byte) 0xe0, (byte) 0xcb, (byte) 0x87, (byte) 0x85, |
| 513 | (byte) 0xd8, (byte) 0x18, (byte) 0x6f, (byte) 0xfe, (byte) 0xa2, (byte) 0x23, (byte) 0x82, (byte) 0xf0, |
| 514 | (byte) 0xe5, (byte) 0x39, (byte) 0x1b, (byte) 0x8c, (byte) 0x93, (byte) 0x11, (byte) 0x49, (byte) 0x72, |
| 515 | (byte) 0x2a, (byte) 0x5b, (byte) 0x25, (byte) 0xff, (byte) 0x4e, (byte) 0x88, (byte) 0x70, (byte) 0x9d, |
| 516 | (byte) 0x9d, (byte) 0xff, (byte) 0xe2, (byte) 0xc0, (byte) 0x7e, (byte) 0xc8, (byte) 0x03, (byte) 0x40, |
| 517 | (byte) 0xbe, (byte) 0x44, (byte) 0x09, (byte) 0xeb, (byte) 0x9e, (byte) 0x8e, (byte) 0x88, (byte) 0xe4, |
| 518 | (byte) 0x98, (byte) 0x82, (byte) 0x06, (byte) 0xa4, (byte) 0x9d, (byte) 0x63, (byte) 0x88, (byte) 0x65, |
| 519 | (byte) 0xa3, (byte) 0x8e, (byte) 0x0d, (byte) 0x22, (byte) 0xf3, (byte) 0x33, (byte) 0xf2, (byte) 0x40, |
| 520 | (byte) 0xe8, (byte) 0x91, (byte) 0x67, (byte) 0x72, (byte) 0x29, (byte) 0x1c, (byte) 0x08, (byte) 0xff, |
| 521 | (byte) 0x54, (byte) 0xa0, (byte) 0xcc, (byte) 0xad, (byte) 0x84, (byte) 0x88, (byte) 0x4b, (byte) 0x3b, |
| 522 | (byte) 0xef, (byte) 0xf9, (byte) 0x5e, (byte) 0xb3, (byte) 0x41, (byte) 0x6a, (byte) 0xbd, (byte) 0x94, |
| 523 | (byte) 0x16, (byte) 0x7d, (byte) 0x9d, (byte) 0x53, (byte) 0x77, (byte) 0xf1, (byte) 0x6a, (byte) 0x95, |
| 524 | (byte) 0x57, (byte) 0xad, (byte) 0x65, (byte) 0x9d, (byte) 0x75, (byte) 0x95, (byte) 0xf6, (byte) 0x6a, |
| 525 | (byte) 0xd2, (byte) 0x88, (byte) 0xea, (byte) 0x5b, (byte) 0xa2, (byte) 0x94, (byte) 0x8f, (byte) 0x5e, |
| 526 | (byte) 0x84, (byte) 0x18, (byte) 0x19, (byte) 0x46, (byte) 0x83, (byte) 0x0b, (byte) 0x6d, (byte) 0x5b, |
| 527 | (byte) 0xb9, (byte) 0xdb, (byte) 0xa4, (byte) 0xe5, (byte) 0x17, (byte) 0x02, (byte) 0x9e, (byte) 0x11, |
| 528 | (byte) 0xed, (byte) 0xd9, (byte) 0x7b, (byte) 0x83, (byte) 0x87, (byte) 0x89, (byte) 0xf3, (byte) 0xe4, |
| 529 | (byte) 0xbf, (byte) 0x0e, (byte) 0xe8, (byte) 0xdc, (byte) 0x55, (byte) 0x9c, (byte) 0xf7, (byte) 0xc9, |
| 530 | (byte) 0xc3, (byte) 0xe2, (byte) 0x2c, (byte) 0xf7, (byte) 0x8c, (byte) 0xaa, (byte) 0x17, (byte) 0x1f, |
| 531 | (byte) 0xd1, (byte) 0xc7, (byte) 0x74, (byte) 0xc7, (byte) 0x8e, (byte) 0x1c, (byte) 0x5b, (byte) 0xd2, |
| 532 | (byte) 0x31, (byte) 0x74, (byte) 0x43, (byte) 0x9a, (byte) 0x52, (byte) 0xbf, (byte) 0x89, (byte) 0xc5, |
| 533 | (byte) 0xb4, (byte) 0x80, (byte) 0x6a, (byte) 0x9e, (byte) 0x05, (byte) 0xdb, (byte) 0xbb, (byte) 0x07, |
| 534 | (byte) 0x8c, (byte) 0x08, (byte) 0x61, (byte) 0xba, (byte) 0xa4, (byte) 0xbc, (byte) 0x80, (byte) 0x3a, |
| 535 | (byte) 0xdd, (byte) 0x3b, (byte) 0x1a, (byte) 0x8c, (byte) 0x21, (byte) 0xd8, (byte) 0xa3, (byte) 0xc0, |
| 536 | (byte) 0xc7, (byte) 0xd1, (byte) 0x08, (byte) 0xe1, (byte) 0x34, (byte) 0x99, (byte) 0xc0, (byte) 0xcf, |
| 537 | (byte) 0x80, (byte) 0xff, (byte) 0xfa, (byte) 0x07, (byte) 0xef, (byte) 0x5c, (byte) 0x45, (byte) 0xe5, |
| 538 | }; |
| 539 | |
| 540 | private static final byte[] SHA384withRSA_Vector2Signature = new byte[] { |
| 541 | (byte) 0xaf, (byte) 0xf7, (byte) 0x7a, (byte) 0xc2, (byte) 0xbb, (byte) 0xb8, (byte) 0xbd, (byte) 0xe3, |
| 542 | (byte) 0x42, (byte) 0xaa, (byte) 0x16, (byte) 0x8a, (byte) 0x52, (byte) 0x6c, (byte) 0x99, (byte) 0x66, |
| 543 | (byte) 0x08, (byte) 0xbe, (byte) 0x15, (byte) 0xd9, (byte) 0x7c, (byte) 0x60, (byte) 0x2c, (byte) 0xac, |
| 544 | (byte) 0x4d, (byte) 0x4c, (byte) 0xf4, (byte) 0xdf, (byte) 0xbc, (byte) 0x16, (byte) 0x58, (byte) 0x0a, |
| 545 | (byte) 0x4e, (byte) 0xde, (byte) 0x8d, (byte) 0xb3, (byte) 0xbd, (byte) 0x03, (byte) 0x4e, (byte) 0x23, |
| 546 | (byte) 0x40, (byte) 0xa5, (byte) 0x80, (byte) 0xae, (byte) 0x83, (byte) 0xb4, (byte) 0x0f, (byte) 0x99, |
| 547 | (byte) 0x44, (byte) 0xc3, (byte) 0x5e, (byte) 0xdb, (byte) 0x59, (byte) 0x1d, (byte) 0xea, (byte) 0x7b, |
| 548 | (byte) 0x4d, (byte) 0xf3, (byte) 0xd2, (byte) 0xad, (byte) 0xbd, (byte) 0x21, (byte) 0x9f, (byte) 0x8e, |
| 549 | (byte) 0x87, (byte) 0x8f, (byte) 0x12, (byte) 0x13, (byte) 0x33, (byte) 0xf1, (byte) 0xc0, (byte) 0x9d, |
| 550 | (byte) 0xe7, (byte) 0xec, (byte) 0x6e, (byte) 0xad, (byte) 0xea, (byte) 0x5d, (byte) 0x69, (byte) 0xbb, |
| 551 | (byte) 0xab, (byte) 0x5b, (byte) 0xd8, (byte) 0x55, (byte) 0x56, (byte) 0xc8, (byte) 0xda, (byte) 0x81, |
| 552 | (byte) 0x41, (byte) 0xfb, (byte) 0xd3, (byte) 0x11, (byte) 0x6c, (byte) 0x97, (byte) 0xa7, (byte) 0xc3, |
| 553 | (byte) 0xf1, (byte) 0x31, (byte) 0xbf, (byte) 0xbe, (byte) 0x3f, (byte) 0xdb, (byte) 0x35, (byte) 0x85, |
| 554 | (byte) 0xb7, (byte) 0xb0, (byte) 0x75, (byte) 0x7f, (byte) 0xaf, (byte) 0xfb, (byte) 0x65, (byte) 0x61, |
| 555 | (byte) 0xc7, (byte) 0x0e, (byte) 0x63, (byte) 0xb5, (byte) 0x7d, (byte) 0x95, (byte) 0xe9, (byte) 0x16, |
| 556 | (byte) 0x9d, (byte) 0x6a, (byte) 0x00, (byte) 0x9f, (byte) 0x5e, (byte) 0xcd, (byte) 0xff, (byte) 0xa6, |
| 557 | (byte) 0xbc, (byte) 0x71, (byte) 0xf2, (byte) 0x2c, (byte) 0xd3, (byte) 0x68, (byte) 0xb9, (byte) 0x3f, |
| 558 | (byte) 0xaa, (byte) 0x06, (byte) 0xf1, (byte) 0x9c, (byte) 0x7e, (byte) 0xca, (byte) 0x4a, (byte) 0xfe, |
| 559 | (byte) 0xb1, (byte) 0x73, (byte) 0x19, (byte) 0x80, (byte) 0x05, (byte) 0xa6, (byte) 0x85, (byte) 0x14, |
| 560 | (byte) 0xda, (byte) 0x7a, (byte) 0x16, (byte) 0x7a, (byte) 0xc2, (byte) 0x46, (byte) 0x57, (byte) 0xa7, |
| 561 | (byte) 0xc0, (byte) 0xbf, (byte) 0xcd, (byte) 0xdc, (byte) 0x2f, (byte) 0x64, (byte) 0xf6, (byte) 0x6d, |
| 562 | (byte) 0xdc, (byte) 0xcb, (byte) 0x5a, (byte) 0x29, (byte) 0x95, (byte) 0x1c, (byte) 0xfe, (byte) 0xf2, |
| 563 | (byte) 0xda, (byte) 0x7e, (byte) 0xcb, (byte) 0x26, (byte) 0x12, (byte) 0xc6, (byte) 0xb0, (byte) 0xba, |
| 564 | (byte) 0x84, (byte) 0x9b, (byte) 0x4f, (byte) 0xba, (byte) 0x1b, (byte) 0x78, (byte) 0x25, (byte) 0xb8, |
| 565 | (byte) 0x8f, (byte) 0x2e, (byte) 0x51, (byte) 0x5f, (byte) 0x9e, (byte) 0xfc, (byte) 0x40, (byte) 0xbc, |
| 566 | (byte) 0x85, (byte) 0xcd, (byte) 0x86, (byte) 0x7f, (byte) 0x88, (byte) 0xc5, (byte) 0xaa, (byte) 0x2b, |
| 567 | (byte) 0x78, (byte) 0xb1, (byte) 0x9c, (byte) 0x51, (byte) 0x9a, (byte) 0xe1, (byte) 0xe1, (byte) 0xc0, |
| 568 | (byte) 0x40, (byte) 0x47, (byte) 0xcb, (byte) 0xa4, (byte) 0xb7, (byte) 0x6c, (byte) 0x31, (byte) 0xf2, |
| 569 | (byte) 0xc8, (byte) 0x9a, (byte) 0xad, (byte) 0x0b, (byte) 0xd3, (byte) 0xf6, (byte) 0x85, (byte) 0x9a, |
| 570 | (byte) 0x8f, (byte) 0x4f, (byte) 0xc9, (byte) 0xd8, (byte) 0x33, (byte) 0x7c, (byte) 0x45, (byte) 0x30, |
| 571 | (byte) 0xea, (byte) 0x17, (byte) 0xd3, (byte) 0xe3, (byte) 0x90, (byte) 0x2c, (byte) 0xda, (byte) 0xde, |
| 572 | (byte) 0x41, (byte) 0x17, (byte) 0x3f, (byte) 0x08, (byte) 0xb9, (byte) 0x34, (byte) 0xc0, (byte) 0xd1, |
| 573 | }; |
| 574 | |
| 575 | private static final byte[] SHA512withRSA_Vector2Signature = new byte[] { |
| 576 | (byte) 0x19, (byte) 0xe2, (byte) 0xe5, (byte) 0xf3, (byte) 0x18, (byte) 0x83, (byte) 0xec, (byte) 0xf0, |
| 577 | (byte) 0xab, (byte) 0x50, (byte) 0x05, (byte) 0x4b, (byte) 0x5f, (byte) 0x22, (byte) 0xfc, (byte) 0x82, |
| 578 | (byte) 0x6d, (byte) 0xca, (byte) 0xe7, (byte) 0xbe, (byte) 0x23, (byte) 0x94, (byte) 0xfa, (byte) 0xf9, |
| 579 | (byte) 0xa4, (byte) 0x8a, (byte) 0x95, (byte) 0x4d, (byte) 0x14, (byte) 0x08, (byte) 0x8b, (byte) 0x5e, |
| 580 | (byte) 0x03, (byte) 0x1b, (byte) 0x74, (byte) 0xde, (byte) 0xc1, (byte) 0x45, (byte) 0x9c, (byte) 0xce, |
| 581 | (byte) 0x1d, (byte) 0xac, (byte) 0xab, (byte) 0xd3, (byte) 0xa8, (byte) 0xc3, (byte) 0xca, (byte) 0x67, |
| 582 | (byte) 0x80, (byte) 0xf6, (byte) 0x03, (byte) 0x46, (byte) 0x65, (byte) 0x77, (byte) 0x59, (byte) 0xbb, |
| 583 | (byte) 0xb8, (byte) 0x83, (byte) 0xee, (byte) 0xc2, (byte) 0x3e, (byte) 0x78, (byte) 0xdd, (byte) 0x89, |
| 584 | (byte) 0xcd, (byte) 0x9b, (byte) 0x78, (byte) 0x35, (byte) 0xa9, (byte) 0x09, (byte) 0xc8, (byte) 0x77, |
| 585 | (byte) 0xdd, (byte) 0xd3, (byte) 0xa0, (byte) 0x64, (byte) 0xb0, (byte) 0x74, (byte) 0x48, (byte) 0x51, |
| 586 | (byte) 0x4f, (byte) 0xa0, (byte) 0xae, (byte) 0x33, (byte) 0xb3, (byte) 0x28, (byte) 0xb0, (byte) 0xa8, |
| 587 | (byte) 0x78, (byte) 0x8f, (byte) 0xa2, (byte) 0x32, (byte) 0xa6, (byte) 0x0a, (byte) 0xaa, (byte) 0x09, |
| 588 | (byte) 0xb5, (byte) 0x8d, (byte) 0x4c, (byte) 0x44, (byte) 0x46, (byte) 0xb4, (byte) 0xd2, (byte) 0x06, |
| 589 | (byte) 0x6b, (byte) 0x8c, (byte) 0x51, (byte) 0x6e, (byte) 0x9c, (byte) 0xfa, (byte) 0x1f, (byte) 0x94, |
| 590 | (byte) 0x3e, (byte) 0x19, (byte) 0x9c, (byte) 0x63, (byte) 0xfe, (byte) 0xa9, (byte) 0x9a, (byte) 0xe3, |
| 591 | (byte) 0x6c, (byte) 0x82, (byte) 0x64, (byte) 0x5f, (byte) 0xca, (byte) 0xc2, (byte) 0x8d, (byte) 0x66, |
| 592 | (byte) 0xbe, (byte) 0x12, (byte) 0x6e, (byte) 0xb6, (byte) 0x35, (byte) 0x6d, (byte) 0xaa, (byte) 0xed, |
| 593 | (byte) 0x4b, (byte) 0x50, (byte) 0x08, (byte) 0x1c, (byte) 0xbf, (byte) 0x07, (byte) 0x70, (byte) 0x78, |
| 594 | (byte) 0xc0, (byte) 0xbb, (byte) 0xc5, (byte) 0x8d, (byte) 0x6c, (byte) 0x8d, (byte) 0x35, (byte) 0xff, |
| 595 | (byte) 0x04, (byte) 0x81, (byte) 0xd8, (byte) 0xf4, (byte) 0xd2, (byte) 0x4a, (byte) 0xc3, (byte) 0x05, |
| 596 | (byte) 0x23, (byte) 0xcb, (byte) 0xeb, (byte) 0x20, (byte) 0xb1, (byte) 0xd4, (byte) 0x2d, (byte) 0xd8, |
| 597 | (byte) 0x7a, (byte) 0xd4, (byte) 0x7e, (byte) 0xf6, (byte) 0xa9, (byte) 0xe8, (byte) 0x72, (byte) 0x69, |
| 598 | (byte) 0xfe, (byte) 0xab, (byte) 0x54, (byte) 0x4d, (byte) 0xd1, (byte) 0xf4, (byte) 0x6b, (byte) 0x83, |
| 599 | (byte) 0x31, (byte) 0x17, (byte) 0xed, (byte) 0x26, (byte) 0xe9, (byte) 0xd2, (byte) 0x5b, (byte) 0xad, |
| 600 | (byte) 0x42, (byte) 0x42, (byte) 0xa5, (byte) 0x8f, (byte) 0x98, (byte) 0x7c, (byte) 0x1b, (byte) 0x5c, |
| 601 | (byte) 0x8e, (byte) 0x88, (byte) 0x56, (byte) 0x20, (byte) 0x8e, (byte) 0x48, (byte) 0xf9, (byte) 0x4d, |
| 602 | (byte) 0x82, (byte) 0x91, (byte) 0xcb, (byte) 0xc8, (byte) 0x1c, (byte) 0x7c, (byte) 0xa5, (byte) 0x69, |
| 603 | (byte) 0x1b, (byte) 0x40, (byte) 0xc2, (byte) 0x4c, (byte) 0x25, (byte) 0x16, (byte) 0x4f, (byte) 0xfa, |
| 604 | (byte) 0x09, (byte) 0xeb, (byte) 0xf5, (byte) 0x6c, (byte) 0x55, (byte) 0x3c, (byte) 0x6e, (byte) 0xf7, |
| 605 | (byte) 0xc0, (byte) 0xc1, (byte) 0x34, (byte) 0xd1, (byte) 0x53, (byte) 0xa3, (byte) 0x69, (byte) 0x64, |
| 606 | (byte) 0xee, (byte) 0xf4, (byte) 0xf9, (byte) 0xc7, (byte) 0x96, (byte) 0x60, (byte) 0x84, (byte) 0x87, |
| 607 | (byte) 0xb4, (byte) 0xc7, (byte) 0x3c, (byte) 0x26, (byte) 0xa7, (byte) 0x3a, (byte) 0xbf, (byte) 0x95, |
| 608 | }; |
| 609 | |
| 610 | private static final byte[] MD5withRSA_Vector2Signature = new byte[] { |
| 611 | (byte) 0x04, (byte) 0x17, (byte) 0x83, (byte) 0x10, (byte) 0xe2, (byte) 0x6e, (byte) 0xdf, (byte) 0xa9, |
| 612 | (byte) 0xae, (byte) 0xd2, (byte) 0xdc, (byte) 0x5f, (byte) 0x70, (byte) 0x1d, (byte) 0xaf, (byte) 0x54, |
| 613 | (byte) 0xc0, (byte) 0x5f, (byte) 0x0b, (byte) 0x2c, (byte) 0xe6, (byte) 0xd0, (byte) 0x00, (byte) 0x18, |
| 614 | (byte) 0x4c, (byte) 0xf6, (byte) 0x8f, (byte) 0x18, (byte) 0x10, (byte) 0x74, (byte) 0x90, (byte) 0x99, |
| 615 | (byte) 0xa9, (byte) 0x90, (byte) 0x3c, (byte) 0x5a, (byte) 0x38, (byte) 0xd3, (byte) 0x3d, (byte) 0x48, |
| 616 | (byte) 0xcf, (byte) 0x31, (byte) 0xaf, (byte) 0x12, (byte) 0x98, (byte) 0xfb, (byte) 0x66, (byte) 0xe8, |
| 617 | (byte) 0x58, (byte) 0xec, (byte) 0xca, (byte) 0xe1, (byte) 0x42, (byte) 0xf9, (byte) 0x84, (byte) 0x17, |
| 618 | (byte) 0x6f, (byte) 0x4c, (byte) 0x3e, (byte) 0xc4, (byte) 0x40, (byte) 0xc6, (byte) 0x70, (byte) 0xb0, |
| 619 | (byte) 0x38, (byte) 0xf3, (byte) 0x47, (byte) 0xeb, (byte) 0x6f, (byte) 0xcb, (byte) 0xea, (byte) 0x21, |
| 620 | (byte) 0x41, (byte) 0xf3, (byte) 0xa0, (byte) 0x3e, (byte) 0x42, (byte) 0xad, (byte) 0xa5, (byte) 0xad, |
| 621 | (byte) 0x5d, (byte) 0x2c, (byte) 0x1a, (byte) 0x8e, (byte) 0x3e, (byte) 0xb3, (byte) 0xa5, (byte) 0x78, |
| 622 | (byte) 0x3d, (byte) 0x56, (byte) 0x09, (byte) 0x93, (byte) 0xc9, (byte) 0x93, (byte) 0xd3, (byte) 0xd2, |
| 623 | (byte) 0x9a, (byte) 0xc5, (byte) 0xa5, (byte) 0x2e, (byte) 0xb2, (byte) 0xd8, (byte) 0x37, (byte) 0xc7, |
| 624 | (byte) 0x13, (byte) 0x1a, (byte) 0x0b, (byte) 0xda, (byte) 0x50, (byte) 0x28, (byte) 0x6d, (byte) 0x47, |
| 625 | (byte) 0x65, (byte) 0x52, (byte) 0xcd, (byte) 0xe7, (byte) 0xec, (byte) 0x57, (byte) 0x00, (byte) 0x41, |
| 626 | (byte) 0x34, (byte) 0x28, (byte) 0xb9, (byte) 0x8b, (byte) 0x03, (byte) 0x41, (byte) 0xb6, (byte) 0xd5, |
| 627 | (byte) 0xa8, (byte) 0xef, (byte) 0xd3, (byte) 0xdd, (byte) 0x80, (byte) 0xd5, (byte) 0x69, (byte) 0xe4, |
| 628 | (byte) 0xf0, (byte) 0x4d, (byte) 0xa4, (byte) 0x7d, (byte) 0x60, (byte) 0x2f, (byte) 0xef, (byte) 0x79, |
| 629 | (byte) 0x07, (byte) 0x75, (byte) 0xeb, (byte) 0xf7, (byte) 0x4b, (byte) 0x43, (byte) 0x41, (byte) 0xdb, |
| 630 | (byte) 0x33, (byte) 0xad, (byte) 0x9c, (byte) 0x7b, (byte) 0x78, (byte) 0x83, (byte) 0x34, (byte) 0x77, |
| 631 | (byte) 0xe4, (byte) 0x80, (byte) 0xbe, (byte) 0xe6, (byte) 0x6f, (byte) 0xdd, (byte) 0xac, (byte) 0xa5, |
| 632 | (byte) 0x37, (byte) 0xcf, (byte) 0xb5, (byte) 0x44, (byte) 0x11, (byte) 0x77, (byte) 0x96, (byte) 0x45, |
| 633 | (byte) 0xf9, (byte) 0xae, (byte) 0x48, (byte) 0xa6, (byte) 0xbe, (byte) 0x30, (byte) 0x32, (byte) 0xeb, |
| 634 | (byte) 0x43, (byte) 0x6f, (byte) 0x66, (byte) 0x39, (byte) 0x57, (byte) 0xf8, (byte) 0xe6, (byte) 0x60, |
| 635 | (byte) 0x31, (byte) 0xd0, (byte) 0xfc, (byte) 0xcf, (byte) 0x9f, (byte) 0xe5, (byte) 0x3d, (byte) 0xcf, |
| 636 | (byte) 0xbd, (byte) 0x7b, (byte) 0x13, (byte) 0x20, (byte) 0xce, (byte) 0x11, (byte) 0xfd, (byte) 0xe5, |
| 637 | (byte) 0xff, (byte) 0x90, (byte) 0x85, (byte) 0xdf, (byte) 0xca, (byte) 0x3d, (byte) 0xd9, (byte) 0x44, |
| 638 | (byte) 0x16, (byte) 0xc2, (byte) 0x32, (byte) 0x28, (byte) 0xc7, (byte) 0x01, (byte) 0x6d, (byte) 0xea, |
| 639 | (byte) 0xcb, (byte) 0x0d, (byte) 0x85, (byte) 0x08, (byte) 0x6f, (byte) 0xcb, (byte) 0x41, (byte) 0x6a, |
| 640 | (byte) 0x3c, (byte) 0x0f, (byte) 0x3d, (byte) 0x38, (byte) 0xb5, (byte) 0x61, (byte) 0xc5, (byte) 0x64, |
| 641 | (byte) 0x64, (byte) 0x81, (byte) 0x4c, (byte) 0xcd, (byte) 0xd1, (byte) 0x6a, (byte) 0x87, (byte) 0x28, |
| 642 | (byte) 0x02, (byte) 0xaf, (byte) 0x8f, (byte) 0x59, (byte) 0xe5, (byte) 0x67, (byte) 0x25, (byte) 0x00, |
| 643 | }; |
| 644 | |
| 645 | /* |
| 646 | * openssl rsautl -raw -sign -inkey rsa.key | recode ../x1 | sed 's/0x/(byte) 0x/g' |
| 647 | */ |
| 648 | private static final byte[] NONEwithRSA_Vector1Signature = new byte[] { |
| 649 | (byte) 0x35, (byte) 0x43, (byte) 0x38, (byte) 0x44, (byte) 0xAD, (byte) 0x3F, |
| 650 | (byte) 0x97, (byte) 0x02, (byte) 0xFB, (byte) 0x59, (byte) 0x1F, (byte) 0x4A, |
| 651 | (byte) 0x2B, (byte) 0xB9, (byte) 0x06, (byte) 0xEC, (byte) 0x66, (byte) 0xE6, |
| 652 | (byte) 0xD2, (byte) 0xC5, (byte) 0x8B, (byte) 0x7B, (byte) 0xE3, (byte) 0x18, |
| 653 | (byte) 0xBF, (byte) 0x07, (byte) 0xD6, (byte) 0x01, (byte) 0xF9, (byte) 0xD9, |
| 654 | (byte) 0x89, (byte) 0xC4, (byte) 0xDB, (byte) 0x00, (byte) 0x68, (byte) 0xFF, |
| 655 | (byte) 0x9B, (byte) 0x43, (byte) 0x90, (byte) 0xF2, (byte) 0xDB, (byte) 0x83, |
| 656 | (byte) 0xF4, (byte) 0x7E, (byte) 0xC6, (byte) 0x81, (byte) 0x01, (byte) 0x3A, |
| 657 | (byte) 0x0B, (byte) 0xE5, (byte) 0xED, (byte) 0x08, (byte) 0x73, (byte) 0x3E, |
| 658 | (byte) 0xE1, (byte) 0x3F, (byte) 0xDF, (byte) 0x1F, (byte) 0x07, (byte) 0x6D, |
| 659 | (byte) 0x22, (byte) 0x8D, (byte) 0xCC, (byte) 0x4E, (byte) 0xE3, (byte) 0x9A, |
| 660 | (byte) 0xBC, (byte) 0xCC, (byte) 0x8F, (byte) 0x9E, (byte) 0x9B, (byte) 0x02, |
| 661 | (byte) 0x48, (byte) 0x00, (byte) 0xAC, (byte) 0x9F, (byte) 0xA4, (byte) 0x8F, |
| 662 | (byte) 0x87, (byte) 0xA1, (byte) 0xA8, (byte) 0xE6, (byte) 0x9D, (byte) 0xCD, |
| 663 | (byte) 0x8B, (byte) 0x05, (byte) 0xE9, (byte) 0xD2, (byte) 0x05, (byte) 0x8D, |
| 664 | (byte) 0xC9, (byte) 0x95, (byte) 0x16, (byte) 0xD0, (byte) 0xCD, (byte) 0x43, |
| 665 | (byte) 0x25, (byte) 0x8A, (byte) 0x11, (byte) 0x46, (byte) 0xD7, (byte) 0x74, |
| 666 | (byte) 0x4C, (byte) 0xCF, (byte) 0x58, (byte) 0xF9, (byte) 0xA1, (byte) 0x30, |
| 667 | (byte) 0x84, (byte) 0x52, (byte) 0xC9, (byte) 0x01, (byte) 0x5F, (byte) 0x24, |
| 668 | (byte) 0x4C, (byte) 0xB1, (byte) 0x9F, (byte) 0x7D, (byte) 0x12, (byte) 0x38, |
| 669 | (byte) 0x27, (byte) 0x0F, (byte) 0x5E, (byte) 0xFF, (byte) 0xE0, (byte) 0x55, |
| 670 | (byte) 0x8B, (byte) 0xA3, (byte) 0xAD, (byte) 0x60, (byte) 0x35, (byte) 0x83, |
| 671 | (byte) 0x58, (byte) 0xAF, (byte) 0x99, (byte) 0xDE, (byte) 0x3F, (byte) 0x5D, |
| 672 | (byte) 0x80, (byte) 0x80, (byte) 0xFF, (byte) 0x9B, (byte) 0xDE, (byte) 0x5C, |
| 673 | (byte) 0xAB, (byte) 0x97, (byte) 0x43, (byte) 0x64, (byte) 0xD9, (byte) 0x9F, |
| 674 | (byte) 0xFB, (byte) 0x67, (byte) 0x65, (byte) 0xA5, (byte) 0x99, (byte) 0xE7, |
| 675 | (byte) 0xE6, (byte) 0xEB, (byte) 0x05, (byte) 0x95, (byte) 0xFC, (byte) 0x46, |
| 676 | (byte) 0x28, (byte) 0x4B, (byte) 0xD8, (byte) 0x8C, (byte) 0xF5, (byte) 0x0A, |
| 677 | (byte) 0xEB, (byte) 0x1F, (byte) 0x30, (byte) 0xEA, (byte) 0xE7, (byte) 0x67, |
| 678 | (byte) 0x11, (byte) 0x25, (byte) 0xF0, (byte) 0x44, (byte) 0x75, (byte) 0x74, |
| 679 | (byte) 0x94, (byte) 0x06, (byte) 0x78, (byte) 0xD0, (byte) 0x21, (byte) 0xF4, |
| 680 | (byte) 0x3F, (byte) 0xC8, (byte) 0xC4, (byte) 0x4A, (byte) 0x57, (byte) 0xBE, |
| 681 | (byte) 0x02, (byte) 0x3C, (byte) 0x93, (byte) 0xF6, (byte) 0x95, (byte) 0xFB, |
| 682 | (byte) 0xD1, (byte) 0x77, (byte) 0x8B, (byte) 0x43, (byte) 0xF0, (byte) 0xB9, |
| 683 | (byte) 0x7D, (byte) 0xE0, (byte) 0x32, (byte) 0xE1, (byte) 0x72, (byte) 0xB5, |
| 684 | (byte) 0x62, (byte) 0x3F, (byte) 0x86, (byte) 0xC3, (byte) 0xD4, (byte) 0x5F, |
| 685 | (byte) 0x5E, (byte) 0x54, (byte) 0x1B, (byte) 0x5B, (byte) 0xE6, (byte) 0x74, |
| 686 | (byte) 0xA1, (byte) 0x0B, (byte) 0xE5, (byte) 0x18, (byte) 0xD2, (byte) 0x4F, |
| 687 | (byte) 0x93, (byte) 0xF3, (byte) 0x09, (byte) 0x58, (byte) 0xCE, (byte) 0xF0, |
| 688 | (byte) 0xA3, (byte) 0x61, (byte) 0xE4, (byte) 0x6E, (byte) 0x46, (byte) 0x45, |
| 689 | (byte) 0x89, (byte) 0x50, (byte) 0xBD, (byte) 0x03, (byte) 0x3F, (byte) 0x38, |
| 690 | (byte) 0xDA, (byte) 0x5D, (byte) 0xD0, (byte) 0x1B, (byte) 0x1F, (byte) 0xB1, |
| 691 | (byte) 0xEE, (byte) 0x89, (byte) 0x59, (byte) 0xC5, |
| 692 | }; |
| 693 | |
| 694 | public void testGetCommonInstances_Success() throws Exception { |
| 695 | assertNotNull(Signature.getInstance("SHA1withRSA")); |
| 696 | assertNotNull(Signature.getInstance("SHA256withRSA")); |
| 697 | assertNotNull(Signature.getInstance("SHA384withRSA")); |
| 698 | assertNotNull(Signature.getInstance("SHA512withRSA")); |
| 699 | assertNotNull(Signature.getInstance("NONEwithRSA")); |
| 700 | assertNotNull(Signature.getInstance("MD5withRSA")); |
| 701 | assertNotNull(Signature.getInstance("SHA1withDSA")); |
| 702 | } |
| 703 | |
| 704 | public void testVerify_SHA1withRSA_Key_Success() throws Exception { |
| 705 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 706 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 707 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 708 | |
| 709 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 710 | sig.initVerify(pubKey); |
| 711 | sig.update(Vector1Data); |
| 712 | |
| 713 | assertTrue("Signature must match expected signature", |
| 714 | sig.verify(SHA1withRSA_Vector1Signature)); |
| 715 | } |
| 716 | |
| 717 | public void testVerify_SHA256withRSA_Key_Success() throws Exception { |
| 718 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 719 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 720 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 721 | |
| 722 | Signature sig = Signature.getInstance("SHA256withRSA"); |
| 723 | sig.initVerify(pubKey); |
| 724 | sig.update(Vector2Data); |
| 725 | |
| 726 | assertTrue("Signature must match expected signature", |
| 727 | sig.verify(SHA256withRSA_Vector2Signature)); |
| 728 | } |
| 729 | |
| 730 | public void testVerify_SHA384withRSA_Key_Success() throws Exception { |
| 731 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 732 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 733 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 734 | |
| 735 | Signature sig = Signature.getInstance("SHA384withRSA"); |
| 736 | sig.initVerify(pubKey); |
| 737 | sig.update(Vector2Data); |
| 738 | |
| 739 | assertTrue("Signature must match expected signature", |
| 740 | sig.verify(SHA384withRSA_Vector2Signature)); |
| 741 | } |
| 742 | |
| 743 | public void testVerify_SHA512withRSA_Key_Success() throws Exception { |
| 744 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 745 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 746 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 747 | |
| 748 | Signature sig = Signature.getInstance("SHA512withRSA"); |
| 749 | sig.initVerify(pubKey); |
| 750 | sig.update(Vector2Data); |
| 751 | |
| 752 | assertTrue("Signature must match expected signature", |
| 753 | sig.verify(SHA512withRSA_Vector2Signature)); |
| 754 | } |
| 755 | |
| 756 | public void testVerify_MD5withRSA_Key_Success() throws Exception { |
| 757 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 758 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 759 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 760 | |
| 761 | Signature sig = Signature.getInstance("MD5withRSA"); |
| 762 | sig.initVerify(pubKey); |
| 763 | sig.update(Vector2Data); |
| 764 | |
| 765 | assertTrue("Signature must match expected signature", |
| 766 | sig.verify(MD5withRSA_Vector2Signature)); |
| 767 | } |
| 768 | |
| 769 | public void testVerify_SHA1withRSA_Key_InitSignThenInitVerify_Success() throws Exception { |
| 770 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 771 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 772 | RSA_2048_publicExponent); |
| 773 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 774 | |
| 775 | RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 776 | RSA_2048_privateExponent); |
| 777 | PrivateKey privKey = kf.generatePrivate(privKeySpec); |
| 778 | |
| 779 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 780 | |
| 781 | // Start a signing operation |
| 782 | sig.initSign(privKey); |
| 783 | sig.update(Vector2Data); |
| 784 | |
| 785 | // Switch to verify |
| 786 | sig.initVerify(pubKey); |
| 787 | sig.update(Vector1Data); |
| 788 | |
| 789 | assertTrue("Signature must match expected signature", |
| 790 | sig.verify(SHA1withRSA_Vector1Signature)); |
| 791 | } |
| 792 | |
| 793 | public void testVerify_SHA1withRSA_Key_TwoMessages_Success() throws Exception { |
| 794 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 795 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 796 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 797 | |
| 798 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 799 | sig.initVerify(pubKey); |
| 800 | |
| 801 | sig.update(Vector1Data); |
| 802 | assertTrue("First signature must match expected signature", |
| 803 | sig.verify(SHA1withRSA_Vector1Signature)); |
| 804 | |
| 805 | sig.update(Vector2Data); |
| 806 | assertTrue("Second signature must match expected signature", |
| 807 | sig.verify(SHA1withRSA_Vector2Signature)); |
| 808 | } |
| 809 | |
| 810 | public void testVerify_SHA1withRSA_Key_WrongExpectedSignature_Failure() throws Exception { |
| 811 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 812 | RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent); |
| 813 | PublicKey pubKey = kf.generatePublic(keySpec); |
| 814 | |
| 815 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 816 | sig.initVerify(pubKey); |
| 817 | sig.update(Vector1Data); |
| 818 | |
| 819 | assertFalse("Signature should fail to verify", sig.verify(SHA1withRSA_Vector2Signature)); |
| 820 | } |
| 821 | |
| 822 | public void testSign_SHA1withRSA_CrtKeyWithPublicExponent_Success() throws Exception { |
| 823 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 824 | RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(RSA_2048_modulus, |
| 825 | RSA_2048_publicExponent, RSA_2048_privateExponent, null, null, null, null, null); |
| 826 | |
| 827 | // The RI fails on this key which is totally unreasonable. |
| 828 | final PrivateKey privKey; |
| 829 | try { |
| 830 | privKey = kf.generatePrivate(keySpec); |
| 831 | } catch (NullPointerException e) { |
| 832 | if (StandardNames.IS_RI) { |
| 833 | return; |
| 834 | } else { |
| 835 | fail("Private key should be created"); |
| 836 | return; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 841 | sig.initSign(privKey); |
| 842 | sig.update(Vector1Data); |
| 843 | |
| 844 | byte[] signature = sig.sign(); |
| 845 | assertNotNull("Signature must not be null", signature); |
| 846 | assertTrue("Signature should match expected", |
| 847 | Arrays.equals(signature, SHA1withRSA_Vector1Signature)); |
| 848 | |
| 849 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 850 | RSA_2048_publicExponent); |
| 851 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 852 | sig.initVerify(pubKey); |
| 853 | sig.update(Vector1Data); |
| 854 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 855 | } |
| 856 | |
| 857 | public void testSign_SHA1withRSA_CrtKey_NoPrivateExponent_Failure() throws Exception { |
| 858 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 859 | RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(RSA_2048_modulus, |
| 860 | RSA_2048_publicExponent, null, RSA_2048_primeP, RSA_2048_primeQ, null, null, null); |
| 861 | |
| 862 | // Failing on this key early is okay. |
| 863 | final PrivateKey privKey; |
| 864 | try { |
| 865 | privKey = kf.generatePrivate(keySpec); |
| 866 | } catch (NullPointerException e) { |
| 867 | return; |
| 868 | } catch (InvalidKeySpecException e) { |
| 869 | return; |
| 870 | } |
| 871 | |
| 872 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 873 | |
| 874 | try { |
| 875 | sig.initSign(privKey); |
| 876 | fail("Should throw error when private exponent is not available"); |
| 877 | } catch (InvalidKeyException expected) { |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | public void testSign_SHA1withRSA_CrtKey_NoModulus_Failure() throws Exception { |
| 882 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 883 | RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(null, RSA_2048_publicExponent, |
| 884 | RSA_2048_privateExponent, RSA_2048_primeP, RSA_2048_primeQ, null, null, null); |
| 885 | |
| 886 | // Failing on this key early is okay. |
| 887 | final PrivateKey privKey; |
| 888 | try { |
| 889 | privKey = kf.generatePrivate(keySpec); |
| 890 | } catch (NullPointerException e) { |
| 891 | return; |
| 892 | } catch (InvalidKeySpecException e) { |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 897 | |
| 898 | try { |
| 899 | sig.initSign(privKey); |
| 900 | fail("Should throw error when modulus is not available"); |
| 901 | } catch (InvalidKeyException expected) { |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | public void testSign_SHA1withRSA_Key_EmptyKey_Failure() throws Exception { |
| 906 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 907 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(null, null); |
| 908 | |
| 909 | // Failing on this key early is okay. |
| 910 | final PrivateKey privKey; |
| 911 | try { |
| 912 | privKey = kf.generatePrivate(keySpec); |
| 913 | } catch (NullPointerException e) { |
| 914 | return; |
| 915 | } catch (InvalidKeySpecException e) { |
| 916 | return; |
| 917 | } |
| 918 | |
| 919 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 920 | |
| 921 | try { |
| 922 | sig.initSign(privKey); |
| 923 | fail("Should throw error when key is empty"); |
| 924 | } catch (InvalidKeyException expected) { |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | public void testSign_SHA1withRSA_Key_Success() throws Exception { |
| 929 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 930 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 931 | RSA_2048_privateExponent); |
| 932 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 933 | |
| 934 | Signature sig = Signature.getInstance("SHA1withRSA"); |
| 935 | sig.initSign(privKey); |
| 936 | sig.update(Vector1Data); |
| 937 | |
| 938 | byte[] signature = sig.sign(); |
| 939 | assertNotNull("Signature must not be null", signature); |
| 940 | assertTrue("Signature should match expected", |
| 941 | Arrays.equals(signature, SHA1withRSA_Vector1Signature)); |
| 942 | |
| 943 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 944 | RSA_2048_publicExponent); |
| 945 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 946 | sig.initVerify(pubKey); |
| 947 | sig.update(Vector1Data); |
| 948 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 949 | } |
| 950 | |
| 951 | public void testSign_SHA256withRSA_Key_Success() throws Exception { |
| 952 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 953 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 954 | RSA_2048_privateExponent); |
| 955 | |
| 956 | final PrivateKey privKey = kf.generatePrivate(keySpec); |
| 957 | |
| 958 | Signature sig = Signature.getInstance("SHA256withRSA"); |
| 959 | sig.initSign(privKey); |
| 960 | sig.update(Vector2Data); |
| 961 | |
| 962 | byte[] signature = sig.sign(); |
| 963 | assertNotNull("Signature must not be null", signature); |
| 964 | assertTrue("Signature should match expected", |
| 965 | Arrays.equals(signature, SHA256withRSA_Vector2Signature)); |
| 966 | |
| 967 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 968 | RSA_2048_publicExponent); |
| 969 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 970 | sig.initVerify(pubKey); |
| 971 | sig.update(Vector2Data); |
| 972 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 973 | } |
| 974 | |
| 975 | public void testSign_SHA384withRSA_Key_Success() throws Exception { |
| 976 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 977 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 978 | RSA_2048_privateExponent); |
| 979 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 980 | |
| 981 | Signature sig = Signature.getInstance("SHA384withRSA"); |
| 982 | sig.initSign(privKey); |
| 983 | sig.update(Vector2Data); |
| 984 | |
| 985 | byte[] signature = sig.sign(); |
| 986 | assertNotNull("Signature must not be null", signature); |
| 987 | assertTrue("Signature should match expected", |
| 988 | Arrays.equals(signature, SHA384withRSA_Vector2Signature)); |
| 989 | |
| 990 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 991 | RSA_2048_publicExponent); |
| 992 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 993 | sig.initVerify(pubKey); |
| 994 | sig.update(Vector2Data); |
| 995 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 996 | } |
| 997 | |
| 998 | public void testSign_SHA512withRSA_Key_Success() throws Exception { |
| 999 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1000 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 1001 | RSA_2048_privateExponent); |
| 1002 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1003 | |
| 1004 | Signature sig = Signature.getInstance("SHA512withRSA"); |
| 1005 | sig.initSign(privKey); |
| 1006 | sig.update(Vector2Data); |
| 1007 | |
| 1008 | byte[] signature = sig.sign(); |
| 1009 | assertNotNull("Signature must not be null", signature); |
| 1010 | assertTrue("Signature should match expected", |
| 1011 | Arrays.equals(signature, SHA512withRSA_Vector2Signature)); |
| 1012 | |
| 1013 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1014 | RSA_2048_publicExponent); |
| 1015 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1016 | sig.initVerify(pubKey); |
| 1017 | sig.update(Vector2Data); |
| 1018 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 1019 | } |
| 1020 | |
| 1021 | public void testSign_MD5withRSA_Key_Success() throws Exception { |
| 1022 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1023 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 1024 | RSA_2048_privateExponent); |
| 1025 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1026 | |
| 1027 | Signature sig = Signature.getInstance("MD5withRSA"); |
| 1028 | sig.initSign(privKey); |
| 1029 | sig.update(Vector2Data); |
| 1030 | |
| 1031 | byte[] signature = sig.sign(); |
| 1032 | assertNotNull("Signature must not be null", signature); |
| 1033 | assertTrue("Signature should match expected", |
| 1034 | Arrays.equals(signature, MD5withRSA_Vector2Signature)); |
| 1035 | |
| 1036 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1037 | RSA_2048_publicExponent); |
| 1038 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1039 | sig.initVerify(pubKey); |
| 1040 | sig.update(Vector2Data); |
| 1041 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 1042 | } |
| 1043 | |
| 1044 | public void testSign_NONEwithRSA_Key_Success() throws Exception { |
| 1045 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1046 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 1047 | RSA_2048_privateExponent); |
| 1048 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1049 | |
| 1050 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1051 | sig.initSign(privKey); |
| 1052 | sig.update(Vector1Data); |
| 1053 | |
| 1054 | byte[] signature = sig.sign(); |
| 1055 | assertNotNull("Signature must not be null", signature); |
| 1056 | assertTrue("Signature should match expected", |
| 1057 | Arrays.equals(signature, NONEwithRSA_Vector1Signature)); |
| 1058 | |
| 1059 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1060 | RSA_2048_publicExponent); |
| 1061 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1062 | sig.initVerify(pubKey); |
| 1063 | sig.update(Vector1Data); |
| 1064 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 1065 | } |
| 1066 | |
| 1067 | public void testVerify_NONEwithRSA_Key_WrongSignature_Failure() throws Exception { |
| 1068 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1069 | |
| 1070 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1071 | RSA_2048_publicExponent); |
| 1072 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1073 | |
| 1074 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1075 | sig.initVerify(pubKey); |
| 1076 | sig.update(Vector1Data); |
| 1077 | assertFalse("Invalid signature must not verify", sig.verify("Invalid".getBytes())); |
| 1078 | } |
| 1079 | |
| 1080 | public void testSign_NONEwithRSA_Key_DataTooLarge_Failure() throws Exception { |
| 1081 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1082 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 1083 | RSA_2048_privateExponent); |
| 1084 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1085 | |
| 1086 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1087 | sig.initSign(privKey); |
| 1088 | |
| 1089 | final int oneTooBig = RSA_2048_modulus.bitLength() - 10; |
| 1090 | for (int i = 0; i < oneTooBig; i++) { |
| 1091 | sig.update((byte) i); |
| 1092 | } |
| 1093 | |
| 1094 | try { |
| 1095 | sig.sign(); |
| 1096 | fail("Should throw exception when data is too large"); |
| 1097 | } catch (SignatureException expected) { |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | public void testSign_NONEwithRSA_Key_DataTooLarge_SingleByte_Failure() throws Exception { |
| 1102 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1103 | RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus, |
| 1104 | RSA_2048_privateExponent); |
| 1105 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1106 | |
| 1107 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1108 | sig.initSign(privKey); |
| 1109 | |
| 1110 | // This should make it two bytes too big. |
| 1111 | final int oneTooBig = RSA_2048_modulus.bitLength() - 10; |
| 1112 | for (int i = 0; i < oneTooBig; i++) { |
| 1113 | sig.update((byte) i); |
| 1114 | } |
| 1115 | |
| 1116 | try { |
| 1117 | sig.sign(); |
| 1118 | fail("Should throw exception when data is too large"); |
| 1119 | } catch (SignatureException expected) { |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | public void testVerify_NONEwithRSA_Key_DataTooLarge_Failure() throws Exception { |
| 1124 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1125 | |
| 1126 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1127 | RSA_2048_publicExponent); |
| 1128 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1129 | |
| 1130 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1131 | sig.initVerify(pubKey); |
| 1132 | |
| 1133 | // This should make it one bytes too big. |
| 1134 | final int oneTooBig = RSA_2048_modulus.bitLength() + 1; |
| 1135 | final byte[] vector = new byte[oneTooBig]; |
| 1136 | for (int i = 0; i < oneTooBig; i++) { |
| 1137 | vector[i] = (byte) Vector1Data[i % Vector1Data.length]; |
| 1138 | } |
| 1139 | sig.update(vector); |
| 1140 | |
| 1141 | assertFalse("Should not verify when signature is too large", |
| 1142 | sig.verify(NONEwithRSA_Vector1Signature)); |
| 1143 | } |
| 1144 | |
| 1145 | public void testVerify_NONEwithRSA_Key_DataTooLarge_SingleByte_Failure() throws Exception { |
| 1146 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1147 | |
| 1148 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1149 | RSA_2048_publicExponent); |
| 1150 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1151 | |
| 1152 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1153 | sig.initVerify(pubKey); |
| 1154 | |
| 1155 | // This should make it twice as big as it should be. |
| 1156 | final int tooBig = RSA_2048_modulus.bitLength() * 2; |
| 1157 | for (int i = 0; i < tooBig; i++) { |
| 1158 | sig.update((byte) Vector1Data[i % Vector1Data.length]); |
| 1159 | } |
| 1160 | |
| 1161 | assertFalse("Should not verify when signature is too large", |
| 1162 | sig.verify(NONEwithRSA_Vector1Signature)); |
| 1163 | } |
| 1164 | |
| 1165 | public void testVerify_NONEwithRSA_Key_SignatureTooSmall_Failure() throws Exception { |
| 1166 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1167 | |
| 1168 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1169 | RSA_2048_publicExponent); |
| 1170 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1171 | |
| 1172 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1173 | sig.initVerify(pubKey); |
| 1174 | sig.update(Vector1Data); |
| 1175 | |
| 1176 | assertFalse("Invalid signature should not verify", sig.verify("Invalid sig".getBytes())); |
| 1177 | } |
| 1178 | |
| 1179 | public void testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure() throws Exception { |
| 1180 | KeyFactory kf = KeyFactory.getInstance("RSA"); |
| 1181 | |
| 1182 | RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus, |
| 1183 | RSA_2048_publicExponent); |
| 1184 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1185 | |
| 1186 | Signature sig = Signature.getInstance("NONEwithRSA"); |
| 1187 | sig.initVerify(pubKey); |
| 1188 | sig.update(Vector1Data); |
| 1189 | |
| 1190 | byte[] invalidSignature = new byte[NONEwithRSA_Vector1Signature.length * 2]; |
| 1191 | System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, 0, |
| 1192 | NONEwithRSA_Vector1Signature.length); |
| 1193 | System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, |
| 1194 | NONEwithRSA_Vector1Signature.length, NONEwithRSA_Vector1Signature.length); |
| 1195 | |
| 1196 | try { |
| 1197 | sig.verify(invalidSignature); |
| 1198 | fail("Should throw exception when signature is too large"); |
| 1199 | } catch (SignatureException expected) { |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | /* |
| 1204 | * These tests were generated with this DSA private key: |
| 1205 | * |
| 1206 | * -----BEGIN DSA PRIVATE KEY----- |
| 1207 | * MIIBugIBAAKBgQCeYcKJ73epThNnZB8JAf4kE1Pgt5CoTnb+iYJ/esU8TgwgVTCV |
| 1208 | * QoXhQH0njwcN6NyZ77MHlDTWfP+cvmnT60Q3UO9J+OJb2NEQhJfq46UcwE5pynA9 |
| 1209 | * eLkW5f5hXYpasyxhtgE70AF8Mo3h82kOi1jGzwCU+EkqS+raAP9L0L5AIwIVAL/u |
| 1210 | * qg8SNFBy+GAT2PFBARClL1dfAoGAd9R6EsyBfn7rOvvmhm1aEB2tqU+5A10hGuQw |
| 1211 | * lXWOzV7RvQpF7uf3a2UCYNAurz28B90rjjPAk4DZK6dxV3a8jrng1/QjjUEal08s |
| 1212 | * G9VLZuj60lANF6s0MT2kiNiOqKduFwO3D2h8ZHuSuGPkmmcYgSfUCxNI031O9qiP |
| 1213 | * VhctCFECgYAz7i1DhjRGUkCdYQd5tVaI42lhXOV71MTYPbuFOIxTL/hny7Z0PZWR |
| 1214 | * A1blmYE6vrArDEhzpmRvDJZSIMzMfJjUIGu1KO73zpo9siK0xY0/sw5r3QC9txP2 |
| 1215 | * 2Mv3BUIl5TLrs9outQJ0VMwldY2fElgCLWcSVkH44qZwWir1cq+cIwIUEGPDardb |
| 1216 | * pNvWlWgTDD6a6ZTby+M= |
| 1217 | * -----END DSA PRIVATE KEY----- |
| 1218 | * |
| 1219 | */ |
| 1220 | |
| 1221 | private static final BigInteger DSA_priv = new BigInteger(new byte[] { |
| 1222 | (byte) 0x10, (byte) 0x63, (byte) 0xc3, (byte) 0x6a, (byte) 0xb7, (byte) 0x5b, (byte) 0xa4, (byte) 0xdb, |
| 1223 | (byte) 0xd6, (byte) 0x95, (byte) 0x68, (byte) 0x13, (byte) 0x0c, (byte) 0x3e, (byte) 0x9a, (byte) 0xe9, |
| 1224 | (byte) 0x94, (byte) 0xdb, (byte) 0xcb, (byte) 0xe3, |
| 1225 | }); |
| 1226 | |
| 1227 | private static final BigInteger DSA_pub = new BigInteger(new byte[] { |
| 1228 | (byte) 0x33, (byte) 0xee, (byte) 0x2d, (byte) 0x43, (byte) 0x86, (byte) 0x34, (byte) 0x46, (byte) 0x52, |
| 1229 | (byte) 0x40, (byte) 0x9d, (byte) 0x61, (byte) 0x07, (byte) 0x79, (byte) 0xb5, (byte) 0x56, (byte) 0x88, |
| 1230 | (byte) 0xe3, (byte) 0x69, (byte) 0x61, (byte) 0x5c, (byte) 0xe5, (byte) 0x7b, (byte) 0xd4, (byte) 0xc4, |
| 1231 | (byte) 0xd8, (byte) 0x3d, (byte) 0xbb, (byte) 0x85, (byte) 0x38, (byte) 0x8c, (byte) 0x53, (byte) 0x2f, |
| 1232 | (byte) 0xf8, (byte) 0x67, (byte) 0xcb, (byte) 0xb6, (byte) 0x74, (byte) 0x3d, (byte) 0x95, (byte) 0x91, |
| 1233 | (byte) 0x03, (byte) 0x56, (byte) 0xe5, (byte) 0x99, (byte) 0x81, (byte) 0x3a, (byte) 0xbe, (byte) 0xb0, |
| 1234 | (byte) 0x2b, (byte) 0x0c, (byte) 0x48, (byte) 0x73, (byte) 0xa6, (byte) 0x64, (byte) 0x6f, (byte) 0x0c, |
| 1235 | (byte) 0x96, (byte) 0x52, (byte) 0x20, (byte) 0xcc, (byte) 0xcc, (byte) 0x7c, (byte) 0x98, (byte) 0xd4, |
| 1236 | (byte) 0x20, (byte) 0x6b, (byte) 0xb5, (byte) 0x28, (byte) 0xee, (byte) 0xf7, (byte) 0xce, (byte) 0x9a, |
| 1237 | (byte) 0x3d, (byte) 0xb2, (byte) 0x22, (byte) 0xb4, (byte) 0xc5, (byte) 0x8d, (byte) 0x3f, (byte) 0xb3, |
| 1238 | (byte) 0x0e, (byte) 0x6b, (byte) 0xdd, (byte) 0x00, (byte) 0xbd, (byte) 0xb7, (byte) 0x13, (byte) 0xf6, |
| 1239 | (byte) 0xd8, (byte) 0xcb, (byte) 0xf7, (byte) 0x05, (byte) 0x42, (byte) 0x25, (byte) 0xe5, (byte) 0x32, |
| 1240 | (byte) 0xeb, (byte) 0xb3, (byte) 0xda, (byte) 0x2e, (byte) 0xb5, (byte) 0x02, (byte) 0x74, (byte) 0x54, |
| 1241 | (byte) 0xcc, (byte) 0x25, (byte) 0x75, (byte) 0x8d, (byte) 0x9f, (byte) 0x12, (byte) 0x58, (byte) 0x02, |
| 1242 | (byte) 0x2d, (byte) 0x67, (byte) 0x12, (byte) 0x56, (byte) 0x41, (byte) 0xf8, (byte) 0xe2, (byte) 0xa6, |
| 1243 | (byte) 0x70, (byte) 0x5a, (byte) 0x2a, (byte) 0xf5, (byte) 0x72, (byte) 0xaf, (byte) 0x9c, (byte) 0x23, |
| 1244 | }); |
| 1245 | |
| 1246 | private static final BigInteger DSA_P = new BigInteger(new byte[] { |
| 1247 | (byte) 0x00, (byte) 0x9e, (byte) 0x61, (byte) 0xc2, (byte) 0x89, (byte) 0xef, (byte) 0x77, (byte) 0xa9, |
| 1248 | (byte) 0x4e, (byte) 0x13, (byte) 0x67, (byte) 0x64, (byte) 0x1f, (byte) 0x09, (byte) 0x01, (byte) 0xfe, |
| 1249 | (byte) 0x24, (byte) 0x13, (byte) 0x53, (byte) 0xe0, (byte) 0xb7, (byte) 0x90, (byte) 0xa8, (byte) 0x4e, |
| 1250 | (byte) 0x76, (byte) 0xfe, (byte) 0x89, (byte) 0x82, (byte) 0x7f, (byte) 0x7a, (byte) 0xc5, (byte) 0x3c, |
| 1251 | (byte) 0x4e, (byte) 0x0c, (byte) 0x20, (byte) 0x55, (byte) 0x30, (byte) 0x95, (byte) 0x42, (byte) 0x85, |
| 1252 | (byte) 0xe1, (byte) 0x40, (byte) 0x7d, (byte) 0x27, (byte) 0x8f, (byte) 0x07, (byte) 0x0d, (byte) 0xe8, |
| 1253 | (byte) 0xdc, (byte) 0x99, (byte) 0xef, (byte) 0xb3, (byte) 0x07, (byte) 0x94, (byte) 0x34, (byte) 0xd6, |
| 1254 | (byte) 0x7c, (byte) 0xff, (byte) 0x9c, (byte) 0xbe, (byte) 0x69, (byte) 0xd3, (byte) 0xeb, (byte) 0x44, |
| 1255 | (byte) 0x37, (byte) 0x50, (byte) 0xef, (byte) 0x49, (byte) 0xf8, (byte) 0xe2, (byte) 0x5b, (byte) 0xd8, |
| 1256 | (byte) 0xd1, (byte) 0x10, (byte) 0x84, (byte) 0x97, (byte) 0xea, (byte) 0xe3, (byte) 0xa5, (byte) 0x1c, |
| 1257 | (byte) 0xc0, (byte) 0x4e, (byte) 0x69, (byte) 0xca, (byte) 0x70, (byte) 0x3d, (byte) 0x78, (byte) 0xb9, |
| 1258 | (byte) 0x16, (byte) 0xe5, (byte) 0xfe, (byte) 0x61, (byte) 0x5d, (byte) 0x8a, (byte) 0x5a, (byte) 0xb3, |
| 1259 | (byte) 0x2c, (byte) 0x61, (byte) 0xb6, (byte) 0x01, (byte) 0x3b, (byte) 0xd0, (byte) 0x01, (byte) 0x7c, |
| 1260 | (byte) 0x32, (byte) 0x8d, (byte) 0xe1, (byte) 0xf3, (byte) 0x69, (byte) 0x0e, (byte) 0x8b, (byte) 0x58, |
| 1261 | (byte) 0xc6, (byte) 0xcf, (byte) 0x00, (byte) 0x94, (byte) 0xf8, (byte) 0x49, (byte) 0x2a, (byte) 0x4b, |
| 1262 | (byte) 0xea, (byte) 0xda, (byte) 0x00, (byte) 0xff, (byte) 0x4b, (byte) 0xd0, (byte) 0xbe, (byte) 0x40, |
| 1263 | (byte) 0x23, |
| 1264 | }); |
| 1265 | |
| 1266 | private static final BigInteger DSA_Q = new BigInteger(new byte[] { |
| 1267 | (byte) 0x00, (byte) 0xbf, (byte) 0xee, (byte) 0xaa, (byte) 0x0f, (byte) 0x12, (byte) 0x34, (byte) 0x50, |
| 1268 | (byte) 0x72, (byte) 0xf8, (byte) 0x60, (byte) 0x13, (byte) 0xd8, (byte) 0xf1, (byte) 0x41, (byte) 0x01, |
| 1269 | (byte) 0x10, (byte) 0xa5, (byte) 0x2f, (byte) 0x57, (byte) 0x5f, |
| 1270 | }); |
| 1271 | |
| 1272 | private static final BigInteger DSA_G = new BigInteger(new byte[] { |
| 1273 | (byte) 0x77, (byte) 0xd4, (byte) 0x7a, (byte) 0x12, (byte) 0xcc, (byte) 0x81, (byte) 0x7e, (byte) 0x7e, |
| 1274 | (byte) 0xeb, (byte) 0x3a, (byte) 0xfb, (byte) 0xe6, (byte) 0x86, (byte) 0x6d, (byte) 0x5a, (byte) 0x10, |
| 1275 | (byte) 0x1d, (byte) 0xad, (byte) 0xa9, (byte) 0x4f, (byte) 0xb9, (byte) 0x03, (byte) 0x5d, (byte) 0x21, |
| 1276 | (byte) 0x1a, (byte) 0xe4, (byte) 0x30, (byte) 0x95, (byte) 0x75, (byte) 0x8e, (byte) 0xcd, (byte) 0x5e, |
| 1277 | (byte) 0xd1, (byte) 0xbd, (byte) 0x0a, (byte) 0x45, (byte) 0xee, (byte) 0xe7, (byte) 0xf7, (byte) 0x6b, |
| 1278 | (byte) 0x65, (byte) 0x02, (byte) 0x60, (byte) 0xd0, (byte) 0x2e, (byte) 0xaf, (byte) 0x3d, (byte) 0xbc, |
| 1279 | (byte) 0x07, (byte) 0xdd, (byte) 0x2b, (byte) 0x8e, (byte) 0x33, (byte) 0xc0, (byte) 0x93, (byte) 0x80, |
| 1280 | (byte) 0xd9, (byte) 0x2b, (byte) 0xa7, (byte) 0x71, (byte) 0x57, (byte) 0x76, (byte) 0xbc, (byte) 0x8e, |
| 1281 | (byte) 0xb9, (byte) 0xe0, (byte) 0xd7, (byte) 0xf4, (byte) 0x23, (byte) 0x8d, (byte) 0x41, (byte) 0x1a, |
| 1282 | (byte) 0x97, (byte) 0x4f, (byte) 0x2c, (byte) 0x1b, (byte) 0xd5, (byte) 0x4b, (byte) 0x66, (byte) 0xe8, |
| 1283 | (byte) 0xfa, (byte) 0xd2, (byte) 0x50, (byte) 0x0d, (byte) 0x17, (byte) 0xab, (byte) 0x34, (byte) 0x31, |
| 1284 | (byte) 0x3d, (byte) 0xa4, (byte) 0x88, (byte) 0xd8, (byte) 0x8e, (byte) 0xa8, (byte) 0xa7, (byte) 0x6e, |
| 1285 | (byte) 0x17, (byte) 0x03, (byte) 0xb7, (byte) 0x0f, (byte) 0x68, (byte) 0x7c, (byte) 0x64, (byte) 0x7b, |
| 1286 | (byte) 0x92, (byte) 0xb8, (byte) 0x63, (byte) 0xe4, (byte) 0x9a, (byte) 0x67, (byte) 0x18, (byte) 0x81, |
| 1287 | (byte) 0x27, (byte) 0xd4, (byte) 0x0b, (byte) 0x13, (byte) 0x48, (byte) 0xd3, (byte) 0x7d, (byte) 0x4e, |
| 1288 | (byte) 0xf6, (byte) 0xa8, (byte) 0x8f, (byte) 0x56, (byte) 0x17, (byte) 0x2d, (byte) 0x08, (byte) 0x51, |
| 1289 | }); |
| 1290 | |
| 1291 | /** |
| 1292 | * A possible signature using SHA1withDSA of Vector2Data. Note that DSS is |
| 1293 | * randomized, so this won't be the exact signature you'll get out of |
| 1294 | * another signing operation unless you use a fixed RNG. |
| 1295 | */ |
| 1296 | public static final byte[] SHA1withDSA_Vector2Signature = new byte[] { |
| 1297 | (byte) 0x30, (byte) 0x2d, (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0x88, (byte) 0xef, (byte) 0xac, |
| 1298 | (byte) 0x2b, (byte) 0x8b, (byte) 0xe2, (byte) 0x61, (byte) 0xc6, (byte) 0x2b, (byte) 0xea, (byte) 0xd5, |
| 1299 | (byte) 0x96, (byte) 0xbc, (byte) 0xb0, (byte) 0xa1, (byte) 0x30, (byte) 0x0c, (byte) 0x1f, (byte) 0xed, |
| 1300 | (byte) 0x11, (byte) 0x02, (byte) 0x14, (byte) 0x15, (byte) 0xc4, (byte) 0xfc, (byte) 0x82, (byte) 0x6f, |
| 1301 | (byte) 0x17, (byte) 0xdc, (byte) 0x87, (byte) 0x82, (byte) 0x75, (byte) 0x23, (byte) 0xd4, (byte) 0x58, |
| 1302 | (byte) 0xdc, (byte) 0x73, (byte) 0x3d, (byte) 0xf3, (byte) 0x51, (byte) 0xc0, (byte) 0x57, |
| 1303 | }; |
| 1304 | |
| 1305 | public void testSign_SHA1withDSA_Key_Success() throws Exception { |
| 1306 | KeyFactory kf = KeyFactory.getInstance("DSA"); |
| 1307 | DSAPrivateKeySpec keySpec = new DSAPrivateKeySpec(DSA_priv, DSA_P, DSA_Q, DSA_G); |
| 1308 | PrivateKey privKey = kf.generatePrivate(keySpec); |
| 1309 | |
| 1310 | Signature sig = Signature.getInstance("SHA1withDSA"); |
| 1311 | sig.initSign(privKey); |
| 1312 | sig.update(Vector2Data); |
| 1313 | |
| 1314 | byte[] signature = sig.sign(); |
| 1315 | assertNotNull("Signature must not be null", signature); |
| 1316 | |
| 1317 | DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(DSA_pub, DSA_P, DSA_Q, DSA_G); |
| 1318 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1319 | sig.initVerify(pubKey); |
| 1320 | sig.update(Vector2Data); |
| 1321 | assertTrue("Signature must verify correctly", sig.verify(signature)); |
| 1322 | } |
| 1323 | |
| 1324 | public void testVerify_SHA1withDSA_Key_Success() throws Exception { |
| 1325 | KeyFactory kf = KeyFactory.getInstance("DSA"); |
| 1326 | DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(DSA_pub, DSA_P, DSA_Q, DSA_G); |
| 1327 | PublicKey pubKey = kf.generatePublic(pubKeySpec); |
| 1328 | |
| 1329 | Signature sig = Signature.getInstance("SHA1withDSA"); |
| 1330 | sig.initVerify(pubKey); |
| 1331 | sig.update(Vector2Data); |
| 1332 | assertTrue("Signature must verify correctly", sig.verify(SHA1withDSA_Vector2Signature)); |
| 1333 | } |
| 1334 | |
| 1335 | // NetscapeCertRequest looks up Signature algorithms by OID from |
| 1336 | // BC but BC version 1.47 had registration bugs and MD5withRSA was |
| 1337 | // overlooked. http://b/7453821 |
| 1338 | public void testGetInstanceFromOID() throws Exception { |
| 1339 | assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.4"); // MD5withRSA |
| 1340 | assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.5"); // SHA1withRSA |
| 1341 | assertBouncyCastleSignatureFromOID("1.3.14.3.2.29"); // SHA1withRSA |
| 1342 | assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.11"); // SHA256withRSA |
| 1343 | assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.12"); // SHA384withRSA |
| 1344 | assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.13"); // SHA512withRSA |
| 1345 | assertBouncyCastleSignatureFromOID("1.2.840.10040.4.3"); // SHA1withDSA |
| 1346 | } |
| 1347 | |
| 1348 | private void assertBouncyCastleSignatureFromOID(String oid) throws Exception { |
| 1349 | Signature signature = Signature.getInstance(oid, "BC"); |
| 1350 | assertNotNull(oid, signature); |
| 1351 | assertEquals(oid, signature.getAlgorithm()); |
| 1352 | } |
| 1353 | } |