157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom/*
257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * Copyright (C) 2010 The Android Open Source Project
357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom *
457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License");
557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * you may not use this file except in compliance with the License.
657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * You may obtain a copy of the License at
757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom *
857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom *      http://www.apache.org/licenses/LICENSE-2.0
957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom *
1057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * Unless required by applicable law or agreed to in writing, software
1157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS,
1257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * See the License for the specific language governing permissions and
1457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom * limitations under the License.
1557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom */
1657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
1757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrompackage libcore.java.security;
1857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.math.BigInteger;
205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.InvalidKeyException;
213b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstromimport java.security.KeyFactory;
2257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.security.KeyPair;
2357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.security.KeyPairGenerator;
245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.PrivateKey;
2557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.security.Provider;
263b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstromimport java.security.PublicKey;
2757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.security.Security;
283b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstromimport java.security.Signature;
297501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Rootimport java.security.SignatureException;
305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.spec.DSAPrivateKeySpec;
315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.spec.DSAPublicKeySpec;
32746a236e2be5dee62c482e27f4c682496d071d8bKenny Rootimport java.security.spec.InvalidKeySpecException;
335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.spec.RSAPrivateCrtKeySpec;
345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.spec.RSAPrivateKeySpec;
355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.security.spec.RSAPublicKeySpec;
363b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstromimport java.security.spec.X509EncodedKeySpec;
375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Rootimport java.util.Arrays;
3857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.util.HashMap;
3957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.util.Map;
4057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport java.util.Set;
4157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstromimport junit.framework.TestCase;
4257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
4357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrompublic class SignatureTest extends TestCase {
4457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
4557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    // 20 bytes for DSA
4657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    private final byte[] DATA = new byte[20];
4757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
4857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    public void test_getInstance() throws Exception {
4957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        Provider[] providers = Security.getProviders();
5057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        for (Provider provider : providers) {
5157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            Set<Provider.Service> services = provider.getServices();
5257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            for (Provider.Service service : services) {
5357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                String type = service.getType();
5457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                if (!type.equals("Signature")) {
5557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    continue;
5657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                }
5757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                String algorithm = service.getAlgorithm();
5857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                try {
5957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    KeyPair kp = keyPair(algorithm);
6057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    // Signature.getInstance(String)
6157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    Signature sig1 = Signature.getInstance(algorithm);
6257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    assertEquals(algorithm, sig1.getAlgorithm());
6357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    test_Signature(sig1, kp);
6457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
6557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    // Signature.getInstance(String, Provider)
6657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    Signature sig2 = Signature.getInstance(algorithm, provider);
6757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    assertEquals(algorithm, sig2.getAlgorithm());
6857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    assertEquals(provider, sig2.getProvider());
6957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    test_Signature(sig2, kp);
7057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
7157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    // Signature.getInstance(String, String)
7257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    Signature sig3 = Signature.getInstance(algorithm, provider.getName());
7357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    assertEquals(algorithm, sig3.getAlgorithm());
7457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    assertEquals(provider, sig3.getProvider());
7557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    test_Signature(sig3, kp);
7657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                } catch (Exception e) {
7757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                    throw new Exception("Problem testing Signature." + algorithm, e);
7857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                }
7957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            }
8057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        }
8157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    }
8257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
8357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    private final Map<String, KeyPair> keypairAlgorithmToInstance
8457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            = new HashMap<String, KeyPair>();
8557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
8657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    private KeyPair keyPair(String sigAlgorithm) throws Exception {
8757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        if (sigAlgorithm.endsWith("Encryption")) {
8857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            sigAlgorithm = sigAlgorithm.substring(0, sigAlgorithm.length()-"Encryption".length());
8957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        }
9057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
9157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        String kpAlgorithm;
9257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        // note ECDSA must be before DSA
9357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        if (sigAlgorithm.endsWith("ECDSA")) {
9457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            kpAlgorithm = "EC";
9557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        } else if (sigAlgorithm.endsWith("DSA")) {
9657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            kpAlgorithm = "DSA";
9757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        } else if (sigAlgorithm.endsWith("RSA")) {
9857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            kpAlgorithm = "RSA";
9957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        } else {
10057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            throw new Exception("Unknown KeyPair algorithm for Signature algorithm "
10157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom                                + sigAlgorithm);
10257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        }
10357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
10457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        KeyPair kp = keypairAlgorithmToInstance.get(kpAlgorithm);
10557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        if (kp == null) {
10657f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            kp = KeyPairGenerator.getInstance(kpAlgorithm).generateKeyPair();
10757f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom            keypairAlgorithmToInstance.put(sigAlgorithm, kp);
10857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        }
10957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        return kp;
11057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    }
11157f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
11257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    private void test_Signature(Signature sig, KeyPair keyPair) throws Exception {
11357f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        sig.initSign(keyPair.getPrivate());
11457f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        sig.update(DATA);
11557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        byte[] signature = sig.sign();
11652ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        assertNotNull(sig.getAlgorithm(), signature);
11752ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        assertTrue(sig.getAlgorithm(), signature.length > 0);
11857f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom
11957f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        sig.initVerify(keyPair.getPublic());
12057f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom        sig.update(DATA);
12152ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        assertTrue(sig.getAlgorithm(), sig.verify(signature));
12252ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom
12352ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        // After verify, should be reusable as if we are after initVerify
12452ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        sig.update(DATA);
12552ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom        assertTrue(sig.getAlgorithm(), sig.verify(signature));
12652ec5bcc7d5d042d7ba6d0244d98ee72007a95e4Brian Carlstrom
1277501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        /*
1287501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root         * The RI appears to clear out the input data in RawDSA while calling
1297501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root         * verify a second time.
1307501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root         */
1317501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        if (StandardNames.IS_RI && "NONEwithDSA".equalsIgnoreCase(sig.getAlgorithm())) {
1327501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            try {
1337501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                sig.verify(signature);
1347501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                fail("Expected RI to have a NONEwithDSA bug");
1357501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            } catch (SignatureException bug) {
1367501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            }
1377501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        } else {
1387501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            // Calling Signature.verify a second time should not throw
1397501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            // http://code.google.com/p/android/issues/detail?id=34933
1407501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.verify(signature);
1417501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
14257f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom    }
1433b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom
1443b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    private static final byte[] PK_BYTES = hexToBytes(
1453b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            "30819f300d06092a864886f70d010101050003818d0030818902818100cd769d178f61475fce3001"
1463b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "2604218320c77a427121d3b41dd76756c8fc0c428cd15cb754adc85466f47547b1c85623d9c17fc6"
1473b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "4f202fca21099caf99460c824ad657caa8c2db34996838d32623c4f23c8b6a4e6698603901262619"
1483b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "4840e0896b1a6ec4f6652484aad04569bb6a885b822a10d700224359c632dc7324520cbb3d020301"
1493b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "0001");
1503b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    private static final byte[] CONTENT = hexToBytes(
1513b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            "f2fa9d73656e00fa01edc12e73656e2e7670632e6432004867268c46dd95030b93ce7260423e5c00"
1523b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "fabd4d656d6265727300fa018dc12e73656e2e7670632e643100d7c258dc00fabd44657669636573"
1533b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "00faa54b65797300fa02b5c12e4d2e4b009471968cc68835f8a68dde10f53d19693d480de767e5fb"
1543b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "976f3562324006372300fabdfd04e1f51ef3aa00fa8d00000001a203e202859471968cc68835f8a6"
1553b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "8dde10f53d19693d480de767e5fb976f356232400637230002bab504e1f51ef5810002c29d28463f"
1563b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "0003da8d000001e201eaf2fa9d73656e00fa01edc12e73656e2e7670632e6432004867268c46dd95"
1573b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "030b93ce7260423e5c00fabd4d656d6265727300fa018dc12e73656e2e7670632e643100d7c258dc"
1583b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "00fabd4465766963657300faa54b65797300fa02b5c12e4d2e4b009471968cc68835f8a68dde10f5"
1593b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "3d19693d480de767e5fb976f3562324006372300fabdfd04e1f51ef3aa000003e202859471968cc6"
1603b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "8835f8a68dde10f53d19693d480de767e5fb976f3562324006372300000000019a0a9530819f300d"
1613b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "06092a864886f70d010101050003818d0030818902818100cd769d178f61475fce30012604218320"
1623b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "c77a427121d3b41dd76756c8fc0c428cd15cb754adc85466f47547b1c85623d9c17fc64f202fca21"
1633b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "099caf99460c824ad657caa8c2db34996838d32623c4f23c8b6a4e66986039012626194840e0896b"
1643b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "1a6ec4f6652484aad04569bb6a885b822a10d700224359c632dc7324520cbb3d020301000100");
1653b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    private static final byte[] SIGNATURE = hexToBytes(
1663b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            "b4016456148cd2e9f580470aad63d19c1fee52b38c9dcb5b4d61a7ca369a7277497775d106d86394"
1673b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "a69229184333b5a3e6261d5bcebdb02530ca9909f4d790199eae7c140f7db39dee2232191bdf0bfb"
1683b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "34fdadc44326b9b3f3fa828652bab07f0362ac141c8c3784ebdec44e0b156a5e7bccdc81a56fe954"
1693b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            + "56ac8c0e4ae12d97");
1703b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom
1713b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    private static byte[] hexToBytes(String s) {
1723b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        int len = s.length();
1733b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        byte[] data = new byte[len / 2];
1743b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        for (int i = 0; i < len; i += 2) {
1753b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom            data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
1763b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom                                  + Character.digit(s.charAt(i+1), 16));
1773b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        }
1783b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        return data;
1793b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    }
1803b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom
1813b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    // http://code.google.com/p/android/issues/detail?id=18566
1823b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    // http://b/5038554
1833b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    public void test18566() throws Exception {
1843b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(PK_BYTES);
1853b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
1863b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        PublicKey pk = keyFactory.generatePublic(keySpec);
1873b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom
1883b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        Signature sig = Signature.getInstance("SHA256withRSA");
1893b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        sig.initVerify(pk);
1903b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        sig.update(CONTENT);
1913b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom        assertTrue(sig.verify(SIGNATURE));
1923b7d489ac5cfa5226179dd9a8b2ee6bd72fadf43Brian Carlstrom    }
1935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
1945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    /*
1955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * Test vectors generated with this private key:
1965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     *
1975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * -----BEGIN RSA PRIVATE KEY-----
1985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * MIIEpAIBAAKCAQEA4Ec+irjyKE/rnnQv+XSPoRjtmGM8kvUq63ouvg075gMpvnZq
1995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * 0Q62pRXQ0s/ZvqeTDwwwZTeJn3lYzT6FsB+IGFJNMSWEqUslHjYltUFB7b/uGYgI
2005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * 4buX/Hy0m56qr2jpyY19DtxTu8D6ADQ1bWMF+7zDxwAUBThqu8hzyw8+90JfPTPf
2015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * ezFa4DbSoLZq/UdQOxab8247UWJRW3Ff2oPeryxYrrmr+zCXw8yd2dvl7ylsF2E5
2025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * Ao6KZx5jBW1F9AGI0sQTNJCEXeUsJTTpxrJHjAe9rpKII7YtBmx3cPn2Pz26JH9T
2035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * CER0e+eqqF2FO4vSRKzsPePImrRkU6tNJMOsaQIDAQABAoIBADd4R3al8XaY9ayW
2045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * DfuDobZ1ZOZIvQWXz4q4CHGG8macJ6nsvdSA8Bl6gNBzCebGqW+SUzHlf4tKxvTU
2055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * XtpFojJpwJ/EKMB6Tm7fc4oV3sl/q9Lyu0ehTyDqcvz+TDbgGtp3vRN82NTaELsW
2065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * LpSkZilx8XX5hfoYjwVsuX7igW9Dq503R2Ekhs2owWGWwwgYqZXshdOEZ3kSZ7O/
2075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * IfJzcQppJYYldoQcW2cSwS1L0govMpmtt8E12l6VFavadufK8qO+gFUdBzt4vxFi
2085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * xIrSt/R0OgI47k0lL31efmUzzK5kzLOTYAdaL9HgNOw65c6cQIzL8OJeQRQCFoez
2095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * 3UdUroECgYEA9UGIS8Nzeyki1BGe9F4t7izUy7dfRVBaFXqlAJ+Zxzot8HJKxGAk
2105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * MGMy6omBd2NFRl3G3x4KbxQK/ztzluaomUrF2qloc0cv43dJ0U6z4HXmKdvrNYMz
2115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * im82SdCiZUp6Qv2atr+krE1IHTkLsimwZL3DEcwb4bYxidp8QM3s8rECgYEA6hp0
2125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * LduIHO23KIyH442GjdekCdFaQ/RF1Td6C1cx3b/KLa8oqOE81cCvzsM0fXSjniNa
2135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * PNljPydN4rlPkt9DgzkR2enxz1jyfeLgj/RZZMcg0+whOdx8r8kSlTzeyy81Wi4s
2145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * NaUPrXVMs7IxZkJLo7bjESoriYw4xcFe2yOGkzkCgYBRgo8exv2ZYCmQG68dfjN7
2155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * pfCvJ+mE6tiVrOYr199O5FoiQInyzBUa880XP84EdLywTzhqLNzA4ANrokGfVFeS
2165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * YtRxAL6TGYSj76Bb7PFBV03AebOpXEqD5sQ/MhTW3zLVEt4ZgIXlMeYWuD/X3Z0f
2175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * TiYHwzM9B8VdEH0dOJNYcQKBgQDbT7UPUN6O21P/NMgJMYigUShn2izKBIl3WeWH
2185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * wkQBDa+GZNWegIPRbBZHiTAfZ6nweAYNg0oq29NnV1toqKhCwrAqibPzH8zsiiL+
2195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * OVeVxcbHQitOXXSh6ajzDndZufwtY5wfFWc+hOk6XvFQb0MVODw41Fy9GxQEj0ch
2205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * 3IIyYQKBgQDYEUWTr0FfthLb8ZI3ENVNB0hiBadqO0MZSWjA3/HxHvD2GkozfV/T
2215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * dBu8lkDkR7i2tsR8OsEgQ1fTsMVbqShr2nP2KSlvX6kUbYl2NX08dR51FIaWpAt0
2225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * aFyCzjCQLWOdck/yTV4ulAfuNO3tLjtN9lqpvP623yjQe6aQPxZXaA==
2235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * -----END RSA PRIVATE KEY-----
2245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     *
2255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     */
2265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
2275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger RSA_2048_modulus = new BigInteger(new byte[] {
2285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x00, (byte) 0xe0, (byte) 0x47, (byte) 0x3e, (byte) 0x8a, (byte) 0xb8, (byte) 0xf2, (byte) 0x28,
2295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4f, (byte) 0xeb, (byte) 0x9e, (byte) 0x74, (byte) 0x2f, (byte) 0xf9, (byte) 0x74, (byte) 0x8f,
2305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa1, (byte) 0x18, (byte) 0xed, (byte) 0x98, (byte) 0x63, (byte) 0x3c, (byte) 0x92, (byte) 0xf5,
2315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2a, (byte) 0xeb, (byte) 0x7a, (byte) 0x2e, (byte) 0xbe, (byte) 0x0d, (byte) 0x3b, (byte) 0xe6,
2325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x03, (byte) 0x29, (byte) 0xbe, (byte) 0x76, (byte) 0x6a, (byte) 0xd1, (byte) 0x0e, (byte) 0xb6,
2335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa5, (byte) 0x15, (byte) 0xd0, (byte) 0xd2, (byte) 0xcf, (byte) 0xd9, (byte) 0xbe, (byte) 0xa7,
2345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x93, (byte) 0x0f, (byte) 0x0c, (byte) 0x30, (byte) 0x65, (byte) 0x37, (byte) 0x89, (byte) 0x9f,
2355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x79, (byte) 0x58, (byte) 0xcd, (byte) 0x3e, (byte) 0x85, (byte) 0xb0, (byte) 0x1f, (byte) 0x88,
2365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x18, (byte) 0x52, (byte) 0x4d, (byte) 0x31, (byte) 0x25, (byte) 0x84, (byte) 0xa9, (byte) 0x4b,
2375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x25, (byte) 0x1e, (byte) 0x36, (byte) 0x25, (byte) 0xb5, (byte) 0x41, (byte) 0x41, (byte) 0xed,
2385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbf, (byte) 0xee, (byte) 0x19, (byte) 0x88, (byte) 0x08, (byte) 0xe1, (byte) 0xbb, (byte) 0x97,
2395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfc, (byte) 0x7c, (byte) 0xb4, (byte) 0x9b, (byte) 0x9e, (byte) 0xaa, (byte) 0xaf, (byte) 0x68,
2405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe9, (byte) 0xc9, (byte) 0x8d, (byte) 0x7d, (byte) 0x0e, (byte) 0xdc, (byte) 0x53, (byte) 0xbb,
2415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0xfa, (byte) 0x00, (byte) 0x34, (byte) 0x35, (byte) 0x6d, (byte) 0x63, (byte) 0x05,
2425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfb, (byte) 0xbc, (byte) 0xc3, (byte) 0xc7, (byte) 0x00, (byte) 0x14, (byte) 0x05, (byte) 0x38,
2435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6a, (byte) 0xbb, (byte) 0xc8, (byte) 0x73, (byte) 0xcb, (byte) 0x0f, (byte) 0x3e, (byte) 0xf7,
2445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x42, (byte) 0x5f, (byte) 0x3d, (byte) 0x33, (byte) 0xdf, (byte) 0x7b, (byte) 0x31, (byte) 0x5a,
2455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe0, (byte) 0x36, (byte) 0xd2, (byte) 0xa0, (byte) 0xb6, (byte) 0x6a, (byte) 0xfd, (byte) 0x47,
2465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x50, (byte) 0x3b, (byte) 0x16, (byte) 0x9b, (byte) 0xf3, (byte) 0x6e, (byte) 0x3b, (byte) 0x51,
2475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x62, (byte) 0x51, (byte) 0x5b, (byte) 0x71, (byte) 0x5f, (byte) 0xda, (byte) 0x83, (byte) 0xde,
2485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xaf, (byte) 0x2c, (byte) 0x58, (byte) 0xae, (byte) 0xb9, (byte) 0xab, (byte) 0xfb, (byte) 0x30,
2495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x97, (byte) 0xc3, (byte) 0xcc, (byte) 0x9d, (byte) 0xd9, (byte) 0xdb, (byte) 0xe5, (byte) 0xef,
2505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x29, (byte) 0x6c, (byte) 0x17, (byte) 0x61, (byte) 0x39, (byte) 0x02, (byte) 0x8e, (byte) 0x8a,
2515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x67, (byte) 0x1e, (byte) 0x63, (byte) 0x05, (byte) 0x6d, (byte) 0x45, (byte) 0xf4, (byte) 0x01,
2525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x88, (byte) 0xd2, (byte) 0xc4, (byte) 0x13, (byte) 0x34, (byte) 0x90, (byte) 0x84, (byte) 0x5d,
2535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe5, (byte) 0x2c, (byte) 0x25, (byte) 0x34, (byte) 0xe9, (byte) 0xc6, (byte) 0xb2, (byte) 0x47,
2545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8c, (byte) 0x07, (byte) 0xbd, (byte) 0xae, (byte) 0x92, (byte) 0x88, (byte) 0x23, (byte) 0xb6,
2555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2d, (byte) 0x06, (byte) 0x6c, (byte) 0x77, (byte) 0x70, (byte) 0xf9, (byte) 0xf6, (byte) 0x3f,
2565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3d, (byte) 0xba, (byte) 0x24, (byte) 0x7f, (byte) 0x53, (byte) 0x08, (byte) 0x44, (byte) 0x74,
2575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7b, (byte) 0xe7, (byte) 0xaa, (byte) 0xa8, (byte) 0x5d, (byte) 0x85, (byte) 0x3b, (byte) 0x8b,
2585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd2, (byte) 0x44, (byte) 0xac, (byte) 0xec, (byte) 0x3d, (byte) 0xe3, (byte) 0xc8, (byte) 0x9a,
2595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb4, (byte) 0x64, (byte) 0x53, (byte) 0xab, (byte) 0x4d, (byte) 0x24, (byte) 0xc3, (byte) 0xac,
2605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x69,
2615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
2625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
2635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger RSA_2048_privateExponent = new BigInteger(new byte[] {
2645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x37, (byte) 0x78, (byte) 0x47, (byte) 0x76, (byte) 0xa5, (byte) 0xf1, (byte) 0x76, (byte) 0x98,
2655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf5, (byte) 0xac, (byte) 0x96, (byte) 0x0d, (byte) 0xfb, (byte) 0x83, (byte) 0xa1, (byte) 0xb6,
2665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x75, (byte) 0x64, (byte) 0xe6, (byte) 0x48, (byte) 0xbd, (byte) 0x05, (byte) 0x97, (byte) 0xcf,
2675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8a, (byte) 0xb8, (byte) 0x08, (byte) 0x71, (byte) 0x86, (byte) 0xf2, (byte) 0x66, (byte) 0x9c,
2685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x27, (byte) 0xa9, (byte) 0xec, (byte) 0xbd, (byte) 0xd4, (byte) 0x80, (byte) 0xf0, (byte) 0x19,
2695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7a, (byte) 0x80, (byte) 0xd0, (byte) 0x73, (byte) 0x09, (byte) 0xe6, (byte) 0xc6, (byte) 0xa9,
2705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6f, (byte) 0x92, (byte) 0x53, (byte) 0x31, (byte) 0xe5, (byte) 0x7f, (byte) 0x8b, (byte) 0x4a,
2715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc6, (byte) 0xf4, (byte) 0xd4, (byte) 0x5e, (byte) 0xda, (byte) 0x45, (byte) 0xa2, (byte) 0x32,
2725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x69, (byte) 0xc0, (byte) 0x9f, (byte) 0xc4, (byte) 0x28, (byte) 0xc0, (byte) 0x7a, (byte) 0x4e,
2735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6e, (byte) 0xdf, (byte) 0x73, (byte) 0x8a, (byte) 0x15, (byte) 0xde, (byte) 0xc9, (byte) 0x7f,
2745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xab, (byte) 0xd2, (byte) 0xf2, (byte) 0xbb, (byte) 0x47, (byte) 0xa1, (byte) 0x4f, (byte) 0x20,
2755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xea, (byte) 0x72, (byte) 0xfc, (byte) 0xfe, (byte) 0x4c, (byte) 0x36, (byte) 0xe0, (byte) 0x1a,
2765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xda, (byte) 0x77, (byte) 0xbd, (byte) 0x13, (byte) 0x7c, (byte) 0xd8, (byte) 0xd4, (byte) 0xda,
2775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x10, (byte) 0xbb, (byte) 0x16, (byte) 0x2e, (byte) 0x94, (byte) 0xa4, (byte) 0x66, (byte) 0x29,
2785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x71, (byte) 0xf1, (byte) 0x75, (byte) 0xf9, (byte) 0x85, (byte) 0xfa, (byte) 0x18, (byte) 0x8f,
2795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x05, (byte) 0x6c, (byte) 0xb9, (byte) 0x7e, (byte) 0xe2, (byte) 0x81, (byte) 0x6f, (byte) 0x43,
2805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xab, (byte) 0x9d, (byte) 0x37, (byte) 0x47, (byte) 0x61, (byte) 0x24, (byte) 0x86, (byte) 0xcd,
2815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa8, (byte) 0xc1, (byte) 0x61, (byte) 0x96, (byte) 0xc3, (byte) 0x08, (byte) 0x18, (byte) 0xa9,
2825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x95, (byte) 0xec, (byte) 0x85, (byte) 0xd3, (byte) 0x84, (byte) 0x67, (byte) 0x79, (byte) 0x12,
2835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x67, (byte) 0xb3, (byte) 0xbf, (byte) 0x21, (byte) 0xf2, (byte) 0x73, (byte) 0x71, (byte) 0x0a,
2845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x69, (byte) 0x25, (byte) 0x86, (byte) 0x25, (byte) 0x76, (byte) 0x84, (byte) 0x1c, (byte) 0x5b,
2855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x67, (byte) 0x12, (byte) 0xc1, (byte) 0x2d, (byte) 0x4b, (byte) 0xd2, (byte) 0x0a, (byte) 0x2f,
2865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x32, (byte) 0x99, (byte) 0xad, (byte) 0xb7, (byte) 0xc1, (byte) 0x35, (byte) 0xda, (byte) 0x5e,
2875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x95, (byte) 0x15, (byte) 0xab, (byte) 0xda, (byte) 0x76, (byte) 0xe7, (byte) 0xca, (byte) 0xf2,
2885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa3, (byte) 0xbe, (byte) 0x80, (byte) 0x55, (byte) 0x1d, (byte) 0x07, (byte) 0x3b, (byte) 0x78,
2895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbf, (byte) 0x11, (byte) 0x62, (byte) 0xc4, (byte) 0x8a, (byte) 0xd2, (byte) 0xb7, (byte) 0xf4,
2905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x74, (byte) 0x3a, (byte) 0x02, (byte) 0x38, (byte) 0xee, (byte) 0x4d, (byte) 0x25, (byte) 0x2f,
2915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7d, (byte) 0x5e, (byte) 0x7e, (byte) 0x65, (byte) 0x33, (byte) 0xcc, (byte) 0xae, (byte) 0x64,
2925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcc, (byte) 0xb3, (byte) 0x93, (byte) 0x60, (byte) 0x07, (byte) 0x5a, (byte) 0x2f, (byte) 0xd1,
2935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe0, (byte) 0x34, (byte) 0xec, (byte) 0x3a, (byte) 0xe5, (byte) 0xce, (byte) 0x9c, (byte) 0x40,
2945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8c, (byte) 0xcb, (byte) 0xf0, (byte) 0xe2, (byte) 0x5e, (byte) 0x41, (byte) 0x14, (byte) 0x02,
2955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x16, (byte) 0x87, (byte) 0xb3, (byte) 0xdd, (byte) 0x47, (byte) 0x54, (byte) 0xae, (byte) 0x81,
2965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
2975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
2985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger RSA_2048_publicExponent = new BigInteger(new byte[] {
2995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x01, (byte) 0x00, (byte) 0x01,
3005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
3015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger RSA_2048_primeP = new BigInteger(new byte[] {
3035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x00, (byte) 0xf5, (byte) 0x41, (byte) 0x88, (byte) 0x4b, (byte) 0xc3, (byte) 0x73, (byte) 0x7b,
3045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x29, (byte) 0x22, (byte) 0xd4, (byte) 0x11, (byte) 0x9e, (byte) 0xf4, (byte) 0x5e, (byte) 0x2d,
3055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xee, (byte) 0x2c, (byte) 0xd4, (byte) 0xcb, (byte) 0xb7, (byte) 0x5f, (byte) 0x45, (byte) 0x50,
3065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x5a, (byte) 0x15, (byte) 0x7a, (byte) 0xa5, (byte) 0x00, (byte) 0x9f, (byte) 0x99, (byte) 0xc7,
3075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3a, (byte) 0x2d, (byte) 0xf0, (byte) 0x72, (byte) 0x4a, (byte) 0xc4, (byte) 0x60, (byte) 0x24,
3085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x30, (byte) 0x63, (byte) 0x32, (byte) 0xea, (byte) 0x89, (byte) 0x81, (byte) 0x77, (byte) 0x63,
3095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x45, (byte) 0x46, (byte) 0x5d, (byte) 0xc6, (byte) 0xdf, (byte) 0x1e, (byte) 0x0a, (byte) 0x6f,
3105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x14, (byte) 0x0a, (byte) 0xff, (byte) 0x3b, (byte) 0x73, (byte) 0x96, (byte) 0xe6, (byte) 0xa8,
3115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x99, (byte) 0x4a, (byte) 0xc5, (byte) 0xda, (byte) 0xa9, (byte) 0x68, (byte) 0x73, (byte) 0x47,
3125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2f, (byte) 0xe3, (byte) 0x77, (byte) 0x49, (byte) 0xd1, (byte) 0x4e, (byte) 0xb3, (byte) 0xe0,
3135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x75, (byte) 0xe6, (byte) 0x29, (byte) 0xdb, (byte) 0xeb, (byte) 0x35, (byte) 0x83, (byte) 0x33,
3145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8a, (byte) 0x6f, (byte) 0x36, (byte) 0x49, (byte) 0xd0, (byte) 0xa2, (byte) 0x65, (byte) 0x4a,
3155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7a, (byte) 0x42, (byte) 0xfd, (byte) 0x9a, (byte) 0xb6, (byte) 0xbf, (byte) 0xa4, (byte) 0xac,
3165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4d, (byte) 0x48, (byte) 0x1d, (byte) 0x39, (byte) 0x0b, (byte) 0xb2, (byte) 0x29, (byte) 0xb0,
3175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x64, (byte) 0xbd, (byte) 0xc3, (byte) 0x11, (byte) 0xcc, (byte) 0x1b, (byte) 0xe1, (byte) 0xb6,
3185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x31, (byte) 0x89, (byte) 0xda, (byte) 0x7c, (byte) 0x40, (byte) 0xcd, (byte) 0xec, (byte) 0xf2,
3195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb1,
3205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
3215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger RSA_2048_primeQ = new BigInteger(new byte[] {
3235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x00, (byte) 0xea, (byte) 0x1a, (byte) 0x74, (byte) 0x2d, (byte) 0xdb, (byte) 0x88, (byte) 0x1c,
3245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xed, (byte) 0xb7, (byte) 0x28, (byte) 0x8c, (byte) 0x87, (byte) 0xe3, (byte) 0x8d, (byte) 0x86,
3255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8d, (byte) 0xd7, (byte) 0xa4, (byte) 0x09, (byte) 0xd1, (byte) 0x5a, (byte) 0x43, (byte) 0xf4,
3265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x45, (byte) 0xd5, (byte) 0x37, (byte) 0x7a, (byte) 0x0b, (byte) 0x57, (byte) 0x31, (byte) 0xdd,
3275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbf, (byte) 0xca, (byte) 0x2d, (byte) 0xaf, (byte) 0x28, (byte) 0xa8, (byte) 0xe1, (byte) 0x3c,
3285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd5, (byte) 0xc0, (byte) 0xaf, (byte) 0xce, (byte) 0xc3, (byte) 0x34, (byte) 0x7d, (byte) 0x74,
3295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa3, (byte) 0x9e, (byte) 0x23, (byte) 0x5a, (byte) 0x3c, (byte) 0xd9, (byte) 0x63, (byte) 0x3f,
3305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x27, (byte) 0x4d, (byte) 0xe2, (byte) 0xb9, (byte) 0x4f, (byte) 0x92, (byte) 0xdf, (byte) 0x43,
3315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x83, (byte) 0x39, (byte) 0x11, (byte) 0xd9, (byte) 0xe9, (byte) 0xf1, (byte) 0xcf, (byte) 0x58,
3325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf2, (byte) 0x7d, (byte) 0xe2, (byte) 0xe0, (byte) 0x8f, (byte) 0xf4, (byte) 0x59, (byte) 0x64,
3335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc7, (byte) 0x20, (byte) 0xd3, (byte) 0xec, (byte) 0x21, (byte) 0x39, (byte) 0xdc, (byte) 0x7c,
3345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xaf, (byte) 0xc9, (byte) 0x12, (byte) 0x95, (byte) 0x3c, (byte) 0xde, (byte) 0xcb, (byte) 0x2f,
3355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x35, (byte) 0x5a, (byte) 0x2e, (byte) 0x2c, (byte) 0x35, (byte) 0xa5, (byte) 0x0f, (byte) 0xad,
3365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x75, (byte) 0x4c, (byte) 0xb3, (byte) 0xb2, (byte) 0x31, (byte) 0x66, (byte) 0x42, (byte) 0x4b,
3375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa3, (byte) 0xb6, (byte) 0xe3, (byte) 0x11, (byte) 0x2a, (byte) 0x2b, (byte) 0x89, (byte) 0x8c,
3385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x38, (byte) 0xc5, (byte) 0xc1, (byte) 0x5e, (byte) 0xdb, (byte) 0x23, (byte) 0x86, (byte) 0x93,
3395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x39,
3405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
3415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3427501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    /* Test data is: "Android.\n" */
3435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] Vector1Data = new byte[] {
3445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x41, (byte) 0x6e, (byte) 0x64, (byte) 0x72, (byte) 0x6f, (byte) 0x69, (byte) 0x64, (byte) 0x2e,
3455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x0a,
3465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
3475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] SHA1withRSA_Vector1Signature = {
3495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6d, (byte) 0x5b, (byte) 0xff, (byte) 0x68, (byte) 0xda, (byte) 0x18, (byte) 0x98, (byte) 0x72,
3505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x5c, (byte) 0x1f, (byte) 0x46, (byte) 0x51, (byte) 0x77, (byte) 0x15, (byte) 0x11, (byte) 0xcb,
3515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe0, (byte) 0xb9, (byte) 0x3b, (byte) 0x7d, (byte) 0xf5, (byte) 0x96, (byte) 0x98, (byte) 0x24,
3525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x85, (byte) 0x9d, (byte) 0x3e, (byte) 0xed, (byte) 0x9b, (byte) 0xb2, (byte) 0x8a, (byte) 0x91,
3535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfb, (byte) 0xf6, (byte) 0x85, (byte) 0x64, (byte) 0x74, (byte) 0x18, (byte) 0xb5, (byte) 0x1c,
3545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb3, (byte) 0x8d, (byte) 0x99, (byte) 0x0d, (byte) 0xdf, (byte) 0xaa, (byte) 0xa6, (byte) 0xa1,
3555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc3, (byte) 0xb6, (byte) 0x25, (byte) 0xb3, (byte) 0x06, (byte) 0xe0, (byte) 0xef, (byte) 0x28,
3565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb0, (byte) 0x4d, (byte) 0x50, (byte) 0xc7, (byte) 0x75, (byte) 0x39, (byte) 0xb9, (byte) 0x2c,
3575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x47, (byte) 0xb5, (byte) 0xe2, (byte) 0x96, (byte) 0xf8, (byte) 0xf6, (byte) 0xcb, (byte) 0xa0,
3585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x58, (byte) 0xc9, (byte) 0x3e, (byte) 0xd5, (byte) 0xfc, (byte) 0x26, (byte) 0xd9, (byte) 0x55,
3595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x73, (byte) 0x39, (byte) 0x75, (byte) 0xb3, (byte) 0xb0, (byte) 0x0a, (byte) 0x5f, (byte) 0x5e,
3605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3b, (byte) 0x4a, (byte) 0x2e, (byte) 0xb1, (byte) 0x0e, (byte) 0x7d, (byte) 0xe5, (byte) 0xcc,
3615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x04, (byte) 0x2c, (byte) 0xd1, (byte) 0x0a, (byte) 0x32, (byte) 0xaa, (byte) 0xd9, (byte) 0x8d,
3625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1f, (byte) 0xcb, (byte) 0xe3, (byte) 0x7f, (byte) 0x63, (byte) 0x12, (byte) 0xb1, (byte) 0x98,
3635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x46, (byte) 0x46, (byte) 0x07, (byte) 0xd9, (byte) 0x49, (byte) 0xd2, (byte) 0xbf, (byte) 0xb5,
3645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbc, (byte) 0xbb, (byte) 0xfd, (byte) 0x1c, (byte) 0xd7, (byte) 0x11, (byte) 0x94, (byte) 0xaa,
3655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x5f, (byte) 0x7b, (byte) 0xb2, (byte) 0x0c, (byte) 0x5d, (byte) 0x94, (byte) 0x53, (byte) 0x5e,
3665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x81, (byte) 0x5c, (byte) 0xbb, (byte) 0x1d, (byte) 0x4f, (byte) 0x30, (byte) 0xcd, (byte) 0xf8,
3675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd7, (byte) 0xa5, (byte) 0xfa, (byte) 0x5e, (byte) 0xe0, (byte) 0x19, (byte) 0x3f, (byte) 0xa4,
3685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xaa, (byte) 0x56, (byte) 0x4e, (byte) 0xec, (byte) 0xeb, (byte) 0xee, (byte) 0xa2, (byte) 0x6c,
3695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc9, (byte) 0x4f, (byte) 0xc2, (byte) 0xcc, (byte) 0x2a, (byte) 0xbc, (byte) 0x5b, (byte) 0x09,
3705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x10, (byte) 0x73, (byte) 0x61, (byte) 0x0c, (byte) 0x04, (byte) 0xb6, (byte) 0xb7, (byte) 0x2c,
3715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x37, (byte) 0xd2, (byte) 0xca, (byte) 0x2d, (byte) 0x54, (byte) 0xf2, (byte) 0xf7, (byte) 0x77,
3725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe1, (byte) 0xba, (byte) 0x9f, (byte) 0x29, (byte) 0x07, (byte) 0xa2, (byte) 0x74, (byte) 0xc6,
3735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe9, (byte) 0x1e, (byte) 0xde, (byte) 0xd7, (byte) 0x9c, (byte) 0x4b, (byte) 0xb7, (byte) 0x66,
3745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x52, (byte) 0xe8, (byte) 0xac, (byte) 0xf6, (byte) 0x76, (byte) 0xab, (byte) 0x16, (byte) 0x82,
3755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x96, (byte) 0x87, (byte) 0x40, (byte) 0x0f, (byte) 0xad, (byte) 0x2d, (byte) 0x46, (byte) 0xa6,
3765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x28, (byte) 0x04, (byte) 0x13, (byte) 0xc2, (byte) 0xce, (byte) 0x50, (byte) 0x56, (byte) 0x6d,
3775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbe, (byte) 0x0c, (byte) 0x91, (byte) 0xd0, (byte) 0x8e, (byte) 0x80, (byte) 0x9e, (byte) 0x91,
3785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8f, (byte) 0x62, (byte) 0xb3, (byte) 0x57, (byte) 0xd6, (byte) 0xae, (byte) 0x53, (byte) 0x91,
3795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x83, (byte) 0xe9, (byte) 0x38, (byte) 0x77, (byte) 0x8f, (byte) 0x20, (byte) 0xdd, (byte) 0x13,
3805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7d, (byte) 0x15, (byte) 0x44, (byte) 0x7e, (byte) 0xb5, (byte) 0x00, (byte) 0xd6, (byte) 0x45,
3815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
3825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] Vector2Data = new byte[] {
3845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x54, (byte) 0x68, (byte) 0x69, (byte) 0x73, (byte) 0x20, (byte) 0x69, (byte) 0x73, (byte) 0x20,
3855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x61, (byte) 0x20, (byte) 0x73, (byte) 0x69, (byte) 0x67, (byte) 0x6e, (byte) 0x65, (byte) 0x64,
3865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x20, (byte) 0x6d, (byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x61, (byte) 0x67, (byte) 0x65,
3875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x20, (byte) 0x66, (byte) 0x72, (byte) 0x6f, (byte) 0x6d, (byte) 0x20, (byte) 0x4b, (byte) 0x65,
3885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6e, (byte) 0x6e, (byte) 0x79, (byte) 0x20, (byte) 0x52, (byte) 0x6f, (byte) 0x6f, (byte) 0x74,
3895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2e, (byte) 0x0a,
3905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
3915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
3925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] SHA1withRSA_Vector2Signature = new byte[] {
3935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2e, (byte) 0xa6, (byte) 0x33, (byte) 0xd1, (byte) 0x9d, (byte) 0xfc, (byte) 0x4e, (byte) 0x27,
3945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb3, (byte) 0xa8, (byte) 0x9a, (byte) 0xf2, (byte) 0x48, (byte) 0x62, (byte) 0x15, (byte) 0xa2,
3955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xce, (byte) 0x5f, (byte) 0x2b, (byte) 0x0e, (byte) 0xc5, (byte) 0x26, (byte) 0xba, (byte) 0xd9,
3965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x0f, (byte) 0x60, (byte) 0xeb, (byte) 0xf0, (byte) 0xd5, (byte) 0x5c, (byte) 0x6b, (byte) 0x23,
3975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x11, (byte) 0x95, (byte) 0xa4, (byte) 0xbd, (byte) 0x11, (byte) 0x68, (byte) 0xe7, (byte) 0x3a,
3985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x37, (byte) 0x3d, (byte) 0x79, (byte) 0xb8, (byte) 0x4f, (byte) 0xe9, (byte) 0xa1, (byte) 0x88,
3995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfb, (byte) 0xa9, (byte) 0x8b, (byte) 0x34, (byte) 0xa1, (byte) 0xe0, (byte) 0xca, (byte) 0x11,
4005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdd, (byte) 0xd0, (byte) 0x83, (byte) 0x7f, (byte) 0xc1, (byte) 0x0b, (byte) 0x16, (byte) 0x61,
4015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xac, (byte) 0x09, (byte) 0xa2, (byte) 0xdd, (byte) 0x40, (byte) 0x5b, (byte) 0x8c, (byte) 0x7a,
4025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb2, (byte) 0xb4, (byte) 0x02, (byte) 0x7c, (byte) 0xd4, (byte) 0x9a, (byte) 0xe6, (byte) 0xa5,
4035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1a, (byte) 0x27, (byte) 0x77, (byte) 0x70, (byte) 0xe3, (byte) 0xe3, (byte) 0x71, (byte) 0xc7,
4045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x59, (byte) 0xc7, (byte) 0x9f, (byte) 0xb8, (byte) 0xef, (byte) 0xe7, (byte) 0x15, (byte) 0x02,
4055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x0d, (byte) 0x70, (byte) 0xdc, (byte) 0x2c, (byte) 0xe9, (byte) 0xf7, (byte) 0x63, (byte) 0x2a,
4065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb5, (byte) 0xee, (byte) 0x9f, (byte) 0x29, (byte) 0x56, (byte) 0x86, (byte) 0x99, (byte) 0xb3,
4075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x0f, (byte) 0xe5, (byte) 0x1f, (byte) 0x76, (byte) 0x22, (byte) 0x3b, (byte) 0x7f, (byte) 0xa9,
4085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x9e, (byte) 0xd4, (byte) 0xc4, (byte) 0x83, (byte) 0x5d, (byte) 0x57, (byte) 0xcc, (byte) 0x37,
4095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcb, (byte) 0x9a, (byte) 0x9e, (byte) 0x73, (byte) 0x44, (byte) 0x93, (byte) 0xb4, (byte) 0xf1,
4105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6b, (byte) 0x98, (byte) 0xa0, (byte) 0x57, (byte) 0xbb, (byte) 0x5e, (byte) 0x8f, (byte) 0x89,
4115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x5b, (byte) 0x97, (byte) 0x26, (byte) 0xe4, (byte) 0xd0, (byte) 0x51, (byte) 0x0a, (byte) 0x5a,
4125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb7, (byte) 0x12, (byte) 0x1a, (byte) 0x6d, (byte) 0xb0, (byte) 0x79, (byte) 0x30, (byte) 0x51,
4135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x83, (byte) 0x2e, (byte) 0xe2, (byte) 0x7a, (byte) 0x67, (byte) 0x66, (byte) 0xd3, (byte) 0x95,
4145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xca, (byte) 0xfc, (byte) 0xcb, (byte) 0x92, (byte) 0x79, (byte) 0x32, (byte) 0x26, (byte) 0x86,
4155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe1, (byte) 0x0d, (byte) 0xd8, (byte) 0x19, (byte) 0xfa, (byte) 0x65, (byte) 0x37, (byte) 0xc9,
4165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4c, (byte) 0x2a, (byte) 0xe1, (byte) 0x42, (byte) 0xc7, (byte) 0xd4, (byte) 0xb7, (byte) 0xeb,
4175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1f, (byte) 0xc3, (byte) 0x53, (byte) 0x64, (byte) 0x6f, (byte) 0x2b, (byte) 0x78, (byte) 0x18,
4185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x03, (byte) 0xda, (byte) 0x8d, (byte) 0x62, (byte) 0x24, (byte) 0x70, (byte) 0xab, (byte) 0xe6,
4195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x16, (byte) 0x13, (byte) 0x24, (byte) 0x6b, (byte) 0x5f, (byte) 0xd3, (byte) 0xec, (byte) 0xc1,
4205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x58, (byte) 0x64, (byte) 0xbd, (byte) 0x30, (byte) 0x98, (byte) 0x5e, (byte) 0x33, (byte) 0xce,
4215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x87, (byte) 0x64, (byte) 0x14, (byte) 0x07, (byte) 0x85, (byte) 0x43, (byte) 0x3e, (byte) 0x9f,
4225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x27, (byte) 0x9f, (byte) 0x63, (byte) 0x66, (byte) 0x9d, (byte) 0x26, (byte) 0x19, (byte) 0xc0,
4235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x02, (byte) 0x08, (byte) 0x15, (byte) 0xcb, (byte) 0xb4, (byte) 0xaa, (byte) 0x4a, (byte) 0xc8,
4245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0x09, (byte) 0x15, (byte) 0x7d, (byte) 0x8a, (byte) 0x21, (byte) 0xbc, (byte) 0xa3,
4255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
4265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
4275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] SHA256withRSA_Vector2Signature = new byte[] {
4285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x18, (byte) 0x6e, (byte) 0x31, (byte) 0x1f, (byte) 0x1d, (byte) 0x44, (byte) 0x09, (byte) 0x3e,
4295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa0, (byte) 0xc4, (byte) 0x3d, (byte) 0xb4, (byte) 0x1b, (byte) 0xf2, (byte) 0xd8, (byte) 0xa4,
4305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x59, (byte) 0xab, (byte) 0xb5, (byte) 0x37, (byte) 0x28, (byte) 0xb8, (byte) 0x94, (byte) 0x6b,
4315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6f, (byte) 0x13, (byte) 0x54, (byte) 0xff, (byte) 0xac, (byte) 0x15, (byte) 0x84, (byte) 0xd0,
4325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc9, (byte) 0x15, (byte) 0x5b, (byte) 0x69, (byte) 0x05, (byte) 0xf1, (byte) 0x44, (byte) 0xfd,
4335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xde, (byte) 0xe8, (byte) 0xb4, (byte) 0x12, (byte) 0x59, (byte) 0x9e, (byte) 0x4c, (byte) 0x0b,
4345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd5, (byte) 0x49, (byte) 0x33, (byte) 0x28, (byte) 0xe0, (byte) 0xcb, (byte) 0x87, (byte) 0x85,
4355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd8, (byte) 0x18, (byte) 0x6f, (byte) 0xfe, (byte) 0xa2, (byte) 0x23, (byte) 0x82, (byte) 0xf0,
4365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe5, (byte) 0x39, (byte) 0x1b, (byte) 0x8c, (byte) 0x93, (byte) 0x11, (byte) 0x49, (byte) 0x72,
4375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2a, (byte) 0x5b, (byte) 0x25, (byte) 0xff, (byte) 0x4e, (byte) 0x88, (byte) 0x70, (byte) 0x9d,
4385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x9d, (byte) 0xff, (byte) 0xe2, (byte) 0xc0, (byte) 0x7e, (byte) 0xc8, (byte) 0x03, (byte) 0x40,
4395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbe, (byte) 0x44, (byte) 0x09, (byte) 0xeb, (byte) 0x9e, (byte) 0x8e, (byte) 0x88, (byte) 0xe4,
4405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x98, (byte) 0x82, (byte) 0x06, (byte) 0xa4, (byte) 0x9d, (byte) 0x63, (byte) 0x88, (byte) 0x65,
4415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa3, (byte) 0x8e, (byte) 0x0d, (byte) 0x22, (byte) 0xf3, (byte) 0x33, (byte) 0xf2, (byte) 0x40,
4425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe8, (byte) 0x91, (byte) 0x67, (byte) 0x72, (byte) 0x29, (byte) 0x1c, (byte) 0x08, (byte) 0xff,
4435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x54, (byte) 0xa0, (byte) 0xcc, (byte) 0xad, (byte) 0x84, (byte) 0x88, (byte) 0x4b, (byte) 0x3b,
4445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xef, (byte) 0xf9, (byte) 0x5e, (byte) 0xb3, (byte) 0x41, (byte) 0x6a, (byte) 0xbd, (byte) 0x94,
4455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x16, (byte) 0x7d, (byte) 0x9d, (byte) 0x53, (byte) 0x77, (byte) 0xf1, (byte) 0x6a, (byte) 0x95,
4465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x57, (byte) 0xad, (byte) 0x65, (byte) 0x9d, (byte) 0x75, (byte) 0x95, (byte) 0xf6, (byte) 0x6a,
4475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd2, (byte) 0x88, (byte) 0xea, (byte) 0x5b, (byte) 0xa2, (byte) 0x94, (byte) 0x8f, (byte) 0x5e,
4485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x84, (byte) 0x18, (byte) 0x19, (byte) 0x46, (byte) 0x83, (byte) 0x0b, (byte) 0x6d, (byte) 0x5b,
4495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb9, (byte) 0xdb, (byte) 0xa4, (byte) 0xe5, (byte) 0x17, (byte) 0x02, (byte) 0x9e, (byte) 0x11,
4505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xed, (byte) 0xd9, (byte) 0x7b, (byte) 0x83, (byte) 0x87, (byte) 0x89, (byte) 0xf3, (byte) 0xe4,
4515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbf, (byte) 0x0e, (byte) 0xe8, (byte) 0xdc, (byte) 0x55, (byte) 0x9c, (byte) 0xf7, (byte) 0xc9,
4525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc3, (byte) 0xe2, (byte) 0x2c, (byte) 0xf7, (byte) 0x8c, (byte) 0xaa, (byte) 0x17, (byte) 0x1f,
4535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd1, (byte) 0xc7, (byte) 0x74, (byte) 0xc7, (byte) 0x8e, (byte) 0x1c, (byte) 0x5b, (byte) 0xd2,
4545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x31, (byte) 0x74, (byte) 0x43, (byte) 0x9a, (byte) 0x52, (byte) 0xbf, (byte) 0x89, (byte) 0xc5,
4555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb4, (byte) 0x80, (byte) 0x6a, (byte) 0x9e, (byte) 0x05, (byte) 0xdb, (byte) 0xbb, (byte) 0x07,
4565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8c, (byte) 0x08, (byte) 0x61, (byte) 0xba, (byte) 0xa4, (byte) 0xbc, (byte) 0x80, (byte) 0x3a,
4575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdd, (byte) 0x3b, (byte) 0x1a, (byte) 0x8c, (byte) 0x21, (byte) 0xd8, (byte) 0xa3, (byte) 0xc0,
4585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc7, (byte) 0xd1, (byte) 0x08, (byte) 0xe1, (byte) 0x34, (byte) 0x99, (byte) 0xc0, (byte) 0xcf,
4595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x80, (byte) 0xff, (byte) 0xfa, (byte) 0x07, (byte) 0xef, (byte) 0x5c, (byte) 0x45, (byte) 0xe5,
4605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
4615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
4625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] SHA384withRSA_Vector2Signature = new byte[] {
4635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xaf, (byte) 0xf7, (byte) 0x7a, (byte) 0xc2, (byte) 0xbb, (byte) 0xb8, (byte) 0xbd, (byte) 0xe3,
4645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x42, (byte) 0xaa, (byte) 0x16, (byte) 0x8a, (byte) 0x52, (byte) 0x6c, (byte) 0x99, (byte) 0x66,
4655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x08, (byte) 0xbe, (byte) 0x15, (byte) 0xd9, (byte) 0x7c, (byte) 0x60, (byte) 0x2c, (byte) 0xac,
4665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4d, (byte) 0x4c, (byte) 0xf4, (byte) 0xdf, (byte) 0xbc, (byte) 0x16, (byte) 0x58, (byte) 0x0a,
4675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4e, (byte) 0xde, (byte) 0x8d, (byte) 0xb3, (byte) 0xbd, (byte) 0x03, (byte) 0x4e, (byte) 0x23,
4685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x40, (byte) 0xa5, (byte) 0x80, (byte) 0xae, (byte) 0x83, (byte) 0xb4, (byte) 0x0f, (byte) 0x99,
4695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x44, (byte) 0xc3, (byte) 0x5e, (byte) 0xdb, (byte) 0x59, (byte) 0x1d, (byte) 0xea, (byte) 0x7b,
4705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4d, (byte) 0xf3, (byte) 0xd2, (byte) 0xad, (byte) 0xbd, (byte) 0x21, (byte) 0x9f, (byte) 0x8e,
4715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x87, (byte) 0x8f, (byte) 0x12, (byte) 0x13, (byte) 0x33, (byte) 0xf1, (byte) 0xc0, (byte) 0x9d,
4725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe7, (byte) 0xec, (byte) 0x6e, (byte) 0xad, (byte) 0xea, (byte) 0x5d, (byte) 0x69, (byte) 0xbb,
4735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xab, (byte) 0x5b, (byte) 0xd8, (byte) 0x55, (byte) 0x56, (byte) 0xc8, (byte) 0xda, (byte) 0x81,
4745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x41, (byte) 0xfb, (byte) 0xd3, (byte) 0x11, (byte) 0x6c, (byte) 0x97, (byte) 0xa7, (byte) 0xc3,
4755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf1, (byte) 0x31, (byte) 0xbf, (byte) 0xbe, (byte) 0x3f, (byte) 0xdb, (byte) 0x35, (byte) 0x85,
4765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb7, (byte) 0xb0, (byte) 0x75, (byte) 0x7f, (byte) 0xaf, (byte) 0xfb, (byte) 0x65, (byte) 0x61,
4775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc7, (byte) 0x0e, (byte) 0x63, (byte) 0xb5, (byte) 0x7d, (byte) 0x95, (byte) 0xe9, (byte) 0x16,
4785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x9d, (byte) 0x6a, (byte) 0x00, (byte) 0x9f, (byte) 0x5e, (byte) 0xcd, (byte) 0xff, (byte) 0xa6,
4795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbc, (byte) 0x71, (byte) 0xf2, (byte) 0x2c, (byte) 0xd3, (byte) 0x68, (byte) 0xb9, (byte) 0x3f,
4805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xaa, (byte) 0x06, (byte) 0xf1, (byte) 0x9c, (byte) 0x7e, (byte) 0xca, (byte) 0x4a, (byte) 0xfe,
4815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb1, (byte) 0x73, (byte) 0x19, (byte) 0x80, (byte) 0x05, (byte) 0xa6, (byte) 0x85, (byte) 0x14,
4825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xda, (byte) 0x7a, (byte) 0x16, (byte) 0x7a, (byte) 0xc2, (byte) 0x46, (byte) 0x57, (byte) 0xa7,
4835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0xbf, (byte) 0xcd, (byte) 0xdc, (byte) 0x2f, (byte) 0x64, (byte) 0xf6, (byte) 0x6d,
4845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdc, (byte) 0xcb, (byte) 0x5a, (byte) 0x29, (byte) 0x95, (byte) 0x1c, (byte) 0xfe, (byte) 0xf2,
4855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xda, (byte) 0x7e, (byte) 0xcb, (byte) 0x26, (byte) 0x12, (byte) 0xc6, (byte) 0xb0, (byte) 0xba,
4865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x84, (byte) 0x9b, (byte) 0x4f, (byte) 0xba, (byte) 0x1b, (byte) 0x78, (byte) 0x25, (byte) 0xb8,
4875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8f, (byte) 0x2e, (byte) 0x51, (byte) 0x5f, (byte) 0x9e, (byte) 0xfc, (byte) 0x40, (byte) 0xbc,
4885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x85, (byte) 0xcd, (byte) 0x86, (byte) 0x7f, (byte) 0x88, (byte) 0xc5, (byte) 0xaa, (byte) 0x2b,
4895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x78, (byte) 0xb1, (byte) 0x9c, (byte) 0x51, (byte) 0x9a, (byte) 0xe1, (byte) 0xe1, (byte) 0xc0,
4905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x40, (byte) 0x47, (byte) 0xcb, (byte) 0xa4, (byte) 0xb7, (byte) 0x6c, (byte) 0x31, (byte) 0xf2,
4915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc8, (byte) 0x9a, (byte) 0xad, (byte) 0x0b, (byte) 0xd3, (byte) 0xf6, (byte) 0x85, (byte) 0x9a,
4925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8f, (byte) 0x4f, (byte) 0xc9, (byte) 0xd8, (byte) 0x33, (byte) 0x7c, (byte) 0x45, (byte) 0x30,
4935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xea, (byte) 0x17, (byte) 0xd3, (byte) 0xe3, (byte) 0x90, (byte) 0x2c, (byte) 0xda, (byte) 0xde,
4945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x41, (byte) 0x17, (byte) 0x3f, (byte) 0x08, (byte) 0xb9, (byte) 0x34, (byte) 0xc0, (byte) 0xd1,
4955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
4965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
4975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] SHA512withRSA_Vector2Signature = new byte[] {
4985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x19, (byte) 0xe2, (byte) 0xe5, (byte) 0xf3, (byte) 0x18, (byte) 0x83, (byte) 0xec, (byte) 0xf0,
4995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xab, (byte) 0x50, (byte) 0x05, (byte) 0x4b, (byte) 0x5f, (byte) 0x22, (byte) 0xfc, (byte) 0x82,
5005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6d, (byte) 0xca, (byte) 0xe7, (byte) 0xbe, (byte) 0x23, (byte) 0x94, (byte) 0xfa, (byte) 0xf9,
5015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa4, (byte) 0x8a, (byte) 0x95, (byte) 0x4d, (byte) 0x14, (byte) 0x08, (byte) 0x8b, (byte) 0x5e,
5025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x03, (byte) 0x1b, (byte) 0x74, (byte) 0xde, (byte) 0xc1, (byte) 0x45, (byte) 0x9c, (byte) 0xce,
5035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1d, (byte) 0xac, (byte) 0xab, (byte) 0xd3, (byte) 0xa8, (byte) 0xc3, (byte) 0xca, (byte) 0x67,
5045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x80, (byte) 0xf6, (byte) 0x03, (byte) 0x46, (byte) 0x65, (byte) 0x77, (byte) 0x59, (byte) 0xbb,
5055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb8, (byte) 0x83, (byte) 0xee, (byte) 0xc2, (byte) 0x3e, (byte) 0x78, (byte) 0xdd, (byte) 0x89,
5065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcd, (byte) 0x9b, (byte) 0x78, (byte) 0x35, (byte) 0xa9, (byte) 0x09, (byte) 0xc8, (byte) 0x77,
5075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdd, (byte) 0xd3, (byte) 0xa0, (byte) 0x64, (byte) 0xb0, (byte) 0x74, (byte) 0x48, (byte) 0x51,
5085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4f, (byte) 0xa0, (byte) 0xae, (byte) 0x33, (byte) 0xb3, (byte) 0x28, (byte) 0xb0, (byte) 0xa8,
5095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x78, (byte) 0x8f, (byte) 0xa2, (byte) 0x32, (byte) 0xa6, (byte) 0x0a, (byte) 0xaa, (byte) 0x09,
5105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb5, (byte) 0x8d, (byte) 0x4c, (byte) 0x44, (byte) 0x46, (byte) 0xb4, (byte) 0xd2, (byte) 0x06,
5115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6b, (byte) 0x8c, (byte) 0x51, (byte) 0x6e, (byte) 0x9c, (byte) 0xfa, (byte) 0x1f, (byte) 0x94,
5125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3e, (byte) 0x19, (byte) 0x9c, (byte) 0x63, (byte) 0xfe, (byte) 0xa9, (byte) 0x9a, (byte) 0xe3,
5135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6c, (byte) 0x82, (byte) 0x64, (byte) 0x5f, (byte) 0xca, (byte) 0xc2, (byte) 0x8d, (byte) 0x66,
5145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbe, (byte) 0x12, (byte) 0x6e, (byte) 0xb6, (byte) 0x35, (byte) 0x6d, (byte) 0xaa, (byte) 0xed,
5155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4b, (byte) 0x50, (byte) 0x08, (byte) 0x1c, (byte) 0xbf, (byte) 0x07, (byte) 0x70, (byte) 0x78,
5165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0xbb, (byte) 0xc5, (byte) 0x8d, (byte) 0x6c, (byte) 0x8d, (byte) 0x35, (byte) 0xff,
5175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x04, (byte) 0x81, (byte) 0xd8, (byte) 0xf4, (byte) 0xd2, (byte) 0x4a, (byte) 0xc3, (byte) 0x05,
5185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x23, (byte) 0xcb, (byte) 0xeb, (byte) 0x20, (byte) 0xb1, (byte) 0xd4, (byte) 0x2d, (byte) 0xd8,
5195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7a, (byte) 0xd4, (byte) 0x7e, (byte) 0xf6, (byte) 0xa9, (byte) 0xe8, (byte) 0x72, (byte) 0x69,
5205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfe, (byte) 0xab, (byte) 0x54, (byte) 0x4d, (byte) 0xd1, (byte) 0xf4, (byte) 0x6b, (byte) 0x83,
5215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x31, (byte) 0x17, (byte) 0xed, (byte) 0x26, (byte) 0xe9, (byte) 0xd2, (byte) 0x5b, (byte) 0xad,
5225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x42, (byte) 0x42, (byte) 0xa5, (byte) 0x8f, (byte) 0x98, (byte) 0x7c, (byte) 0x1b, (byte) 0x5c,
5235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x8e, (byte) 0x88, (byte) 0x56, (byte) 0x20, (byte) 0x8e, (byte) 0x48, (byte) 0xf9, (byte) 0x4d,
5245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x82, (byte) 0x91, (byte) 0xcb, (byte) 0xc8, (byte) 0x1c, (byte) 0x7c, (byte) 0xa5, (byte) 0x69,
5255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1b, (byte) 0x40, (byte) 0xc2, (byte) 0x4c, (byte) 0x25, (byte) 0x16, (byte) 0x4f, (byte) 0xfa,
5265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x09, (byte) 0xeb, (byte) 0xf5, (byte) 0x6c, (byte) 0x55, (byte) 0x3c, (byte) 0x6e, (byte) 0xf7,
5275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0xc1, (byte) 0x34, (byte) 0xd1, (byte) 0x53, (byte) 0xa3, (byte) 0x69, (byte) 0x64,
5285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xee, (byte) 0xf4, (byte) 0xf9, (byte) 0xc7, (byte) 0x96, (byte) 0x60, (byte) 0x84, (byte) 0x87,
5295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb4, (byte) 0xc7, (byte) 0x3c, (byte) 0x26, (byte) 0xa7, (byte) 0x3a, (byte) 0xbf, (byte) 0x95,
5305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
5315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
5325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final byte[] MD5withRSA_Vector2Signature = new byte[] {
5335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x04, (byte) 0x17, (byte) 0x83, (byte) 0x10, (byte) 0xe2, (byte) 0x6e, (byte) 0xdf, (byte) 0xa9,
5345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xae, (byte) 0xd2, (byte) 0xdc, (byte) 0x5f, (byte) 0x70, (byte) 0x1d, (byte) 0xaf, (byte) 0x54,
5355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0x5f, (byte) 0x0b, (byte) 0x2c, (byte) 0xe6, (byte) 0xd0, (byte) 0x00, (byte) 0x18,
5365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4c, (byte) 0xf6, (byte) 0x8f, (byte) 0x18, (byte) 0x10, (byte) 0x74, (byte) 0x90, (byte) 0x99,
5375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa9, (byte) 0x90, (byte) 0x3c, (byte) 0x5a, (byte) 0x38, (byte) 0xd3, (byte) 0x3d, (byte) 0x48,
5385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcf, (byte) 0x31, (byte) 0xaf, (byte) 0x12, (byte) 0x98, (byte) 0xfb, (byte) 0x66, (byte) 0xe8,
5395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x58, (byte) 0xec, (byte) 0xca, (byte) 0xe1, (byte) 0x42, (byte) 0xf9, (byte) 0x84, (byte) 0x17,
5405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x6f, (byte) 0x4c, (byte) 0x3e, (byte) 0xc4, (byte) 0x40, (byte) 0xc6, (byte) 0x70, (byte) 0xb0,
5415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x38, (byte) 0xf3, (byte) 0x47, (byte) 0xeb, (byte) 0x6f, (byte) 0xcb, (byte) 0xea, (byte) 0x21,
5425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x41, (byte) 0xf3, (byte) 0xa0, (byte) 0x3e, (byte) 0x42, (byte) 0xad, (byte) 0xa5, (byte) 0xad,
5435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x5d, (byte) 0x2c, (byte) 0x1a, (byte) 0x8e, (byte) 0x3e, (byte) 0xb3, (byte) 0xa5, (byte) 0x78,
5445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3d, (byte) 0x56, (byte) 0x09, (byte) 0x93, (byte) 0xc9, (byte) 0x93, (byte) 0xd3, (byte) 0xd2,
5455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x9a, (byte) 0xc5, (byte) 0xa5, (byte) 0x2e, (byte) 0xb2, (byte) 0xd8, (byte) 0x37, (byte) 0xc7,
5465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x13, (byte) 0x1a, (byte) 0x0b, (byte) 0xda, (byte) 0x50, (byte) 0x28, (byte) 0x6d, (byte) 0x47,
5475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x65, (byte) 0x52, (byte) 0xcd, (byte) 0xe7, (byte) 0xec, (byte) 0x57, (byte) 0x00, (byte) 0x41,
5485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x34, (byte) 0x28, (byte) 0xb9, (byte) 0x8b, (byte) 0x03, (byte) 0x41, (byte) 0xb6, (byte) 0xd5,
5495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xa8, (byte) 0xef, (byte) 0xd3, (byte) 0xdd, (byte) 0x80, (byte) 0xd5, (byte) 0x69, (byte) 0xe4,
5505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf0, (byte) 0x4d, (byte) 0xa4, (byte) 0x7d, (byte) 0x60, (byte) 0x2f, (byte) 0xef, (byte) 0x79,
5515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x07, (byte) 0x75, (byte) 0xeb, (byte) 0xf7, (byte) 0x4b, (byte) 0x43, (byte) 0x41, (byte) 0xdb,
5525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x33, (byte) 0xad, (byte) 0x9c, (byte) 0x7b, (byte) 0x78, (byte) 0x83, (byte) 0x34, (byte) 0x77,
5535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe4, (byte) 0x80, (byte) 0xbe, (byte) 0xe6, (byte) 0x6f, (byte) 0xdd, (byte) 0xac, (byte) 0xa5,
5545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x37, (byte) 0xcf, (byte) 0xb5, (byte) 0x44, (byte) 0x11, (byte) 0x77, (byte) 0x96, (byte) 0x45,
5555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf9, (byte) 0xae, (byte) 0x48, (byte) 0xa6, (byte) 0xbe, (byte) 0x30, (byte) 0x32, (byte) 0xeb,
5565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x43, (byte) 0x6f, (byte) 0x66, (byte) 0x39, (byte) 0x57, (byte) 0xf8, (byte) 0xe6, (byte) 0x60,
5575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x31, (byte) 0xd0, (byte) 0xfc, (byte) 0xcf, (byte) 0x9f, (byte) 0xe5, (byte) 0x3d, (byte) 0xcf,
5585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xbd, (byte) 0x7b, (byte) 0x13, (byte) 0x20, (byte) 0xce, (byte) 0x11, (byte) 0xfd, (byte) 0xe5,
5595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xff, (byte) 0x90, (byte) 0x85, (byte) 0xdf, (byte) 0xca, (byte) 0x3d, (byte) 0xd9, (byte) 0x44,
5605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x16, (byte) 0xc2, (byte) 0x32, (byte) 0x28, (byte) 0xc7, (byte) 0x01, (byte) 0x6d, (byte) 0xea,
5615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcb, (byte) 0x0d, (byte) 0x85, (byte) 0x08, (byte) 0x6f, (byte) 0xcb, (byte) 0x41, (byte) 0x6a,
5625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3c, (byte) 0x0f, (byte) 0x3d, (byte) 0x38, (byte) 0xb5, (byte) 0x61, (byte) 0xc5, (byte) 0x64,
5635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x64, (byte) 0x81, (byte) 0x4c, (byte) 0xcd, (byte) 0xd1, (byte) 0x6a, (byte) 0x87, (byte) 0x28,
5645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x02, (byte) 0xaf, (byte) 0x8f, (byte) 0x59, (byte) 0xe5, (byte) 0x67, (byte) 0x25, (byte) 0x00,
5655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
5665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
5677501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    /*
5687501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root     * openssl rsautl -raw -sign -inkey rsa.key | recode ../x1 | sed 's/0x/(byte) 0x/g'
5697501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root     */
5707501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    private static final byte[] NONEwithRSA_Vector1Signature = new byte[] {
5717501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x35, (byte) 0x43, (byte) 0x38, (byte) 0x44, (byte) 0xAD, (byte) 0x3F,
5727501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x97, (byte) 0x02, (byte) 0xFB, (byte) 0x59, (byte) 0x1F, (byte) 0x4A,
5737501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x2B, (byte) 0xB9, (byte) 0x06, (byte) 0xEC, (byte) 0x66, (byte) 0xE6,
5747501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xD2, (byte) 0xC5, (byte) 0x8B, (byte) 0x7B, (byte) 0xE3, (byte) 0x18,
5757501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xBF, (byte) 0x07, (byte) 0xD6, (byte) 0x01, (byte) 0xF9, (byte) 0xD9,
5767501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x89, (byte) 0xC4, (byte) 0xDB, (byte) 0x00, (byte) 0x68, (byte) 0xFF,
5777501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x9B, (byte) 0x43, (byte) 0x90, (byte) 0xF2, (byte) 0xDB, (byte) 0x83,
5787501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xF4, (byte) 0x7E, (byte) 0xC6, (byte) 0x81, (byte) 0x01, (byte) 0x3A,
5797501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x0B, (byte) 0xE5, (byte) 0xED, (byte) 0x08, (byte) 0x73, (byte) 0x3E,
5807501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xE1, (byte) 0x3F, (byte) 0xDF, (byte) 0x1F, (byte) 0x07, (byte) 0x6D,
5817501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x22, (byte) 0x8D, (byte) 0xCC, (byte) 0x4E, (byte) 0xE3, (byte) 0x9A,
5827501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xBC, (byte) 0xCC, (byte) 0x8F, (byte) 0x9E, (byte) 0x9B, (byte) 0x02,
5837501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x48, (byte) 0x00, (byte) 0xAC, (byte) 0x9F, (byte) 0xA4, (byte) 0x8F,
5847501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x87, (byte) 0xA1, (byte) 0xA8, (byte) 0xE6, (byte) 0x9D, (byte) 0xCD,
5857501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x8B, (byte) 0x05, (byte) 0xE9, (byte) 0xD2, (byte) 0x05, (byte) 0x8D,
5867501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xC9, (byte) 0x95, (byte) 0x16, (byte) 0xD0, (byte) 0xCD, (byte) 0x43,
5877501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x25, (byte) 0x8A, (byte) 0x11, (byte) 0x46, (byte) 0xD7, (byte) 0x74,
5887501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x4C, (byte) 0xCF, (byte) 0x58, (byte) 0xF9, (byte) 0xA1, (byte) 0x30,
5897501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x84, (byte) 0x52, (byte) 0xC9, (byte) 0x01, (byte) 0x5F, (byte) 0x24,
5907501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x4C, (byte) 0xB1, (byte) 0x9F, (byte) 0x7D, (byte) 0x12, (byte) 0x38,
5917501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x27, (byte) 0x0F, (byte) 0x5E, (byte) 0xFF, (byte) 0xE0, (byte) 0x55,
5927501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x8B, (byte) 0xA3, (byte) 0xAD, (byte) 0x60, (byte) 0x35, (byte) 0x83,
5937501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x58, (byte) 0xAF, (byte) 0x99, (byte) 0xDE, (byte) 0x3F, (byte) 0x5D,
5947501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x80, (byte) 0x80, (byte) 0xFF, (byte) 0x9B, (byte) 0xDE, (byte) 0x5C,
5957501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xAB, (byte) 0x97, (byte) 0x43, (byte) 0x64, (byte) 0xD9, (byte) 0x9F,
5967501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xFB, (byte) 0x67, (byte) 0x65, (byte) 0xA5, (byte) 0x99, (byte) 0xE7,
5977501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xE6, (byte) 0xEB, (byte) 0x05, (byte) 0x95, (byte) 0xFC, (byte) 0x46,
5987501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x28, (byte) 0x4B, (byte) 0xD8, (byte) 0x8C, (byte) 0xF5, (byte) 0x0A,
5997501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xEB, (byte) 0x1F, (byte) 0x30, (byte) 0xEA, (byte) 0xE7, (byte) 0x67,
6007501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x11, (byte) 0x25, (byte) 0xF0, (byte) 0x44, (byte) 0x75, (byte) 0x74,
6017501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x94, (byte) 0x06, (byte) 0x78, (byte) 0xD0, (byte) 0x21, (byte) 0xF4,
6027501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x3F, (byte) 0xC8, (byte) 0xC4, (byte) 0x4A, (byte) 0x57, (byte) 0xBE,
6037501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x02, (byte) 0x3C, (byte) 0x93, (byte) 0xF6, (byte) 0x95, (byte) 0xFB,
6047501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xD1, (byte) 0x77, (byte) 0x8B, (byte) 0x43, (byte) 0xF0, (byte) 0xB9,
6057501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x7D, (byte) 0xE0, (byte) 0x32, (byte) 0xE1, (byte) 0x72, (byte) 0xB5,
6067501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x62, (byte) 0x3F, (byte) 0x86, (byte) 0xC3, (byte) 0xD4, (byte) 0x5F,
6077501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x5E, (byte) 0x54, (byte) 0x1B, (byte) 0x5B, (byte) 0xE6, (byte) 0x74,
6087501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xA1, (byte) 0x0B, (byte) 0xE5, (byte) 0x18, (byte) 0xD2, (byte) 0x4F,
6097501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x93, (byte) 0xF3, (byte) 0x09, (byte) 0x58, (byte) 0xCE, (byte) 0xF0,
6107501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xA3, (byte) 0x61, (byte) 0xE4, (byte) 0x6E, (byte) 0x46, (byte) 0x45,
6117501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0x89, (byte) 0x50, (byte) 0xBD, (byte) 0x03, (byte) 0x3F, (byte) 0x38,
6127501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xDA, (byte) 0x5D, (byte) 0xD0, (byte) 0x1B, (byte) 0x1F, (byte) 0xB1,
6137501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        (byte) 0xEE, (byte) 0x89, (byte) 0x59, (byte) 0xC5,
6147501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    };
6157501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
6165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testGetCommonInstances_Success() throws Exception {
6175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("SHA1withRSA"));
6185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("SHA256withRSA"));
6195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("SHA384withRSA"));
6205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("SHA512withRSA"));
6217501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertNotNull(Signature.getInstance("NONEwithRSA"));
6225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("MD5withRSA"));
6235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull(Signature.getInstance("SHA1withDSA"));
6245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA1withRSA_Key_Success() throws Exception {
6275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
6295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
6305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
6325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
6335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
6345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
6365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA1withRSA_Vector1Signature));
6375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA256withRSA_Key_Success() throws Exception {
6405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
6425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
6435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA256withRSA");
6455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
6465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
6475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
6495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA256withRSA_Vector2Signature));
6505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA384withRSA_Key_Success() throws Exception {
6535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
6555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
6565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA384withRSA");
6585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
6595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
6605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
6625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA384withRSA_Vector2Signature));
6635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA512withRSA_Key_Success() throws Exception {
6665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
6685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
6695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA512withRSA");
6715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
6725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
6735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
6755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA512withRSA_Vector2Signature));
6765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_MD5withRSA_Key_Success() throws Exception {
6795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
6815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
6825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("MD5withRSA");
6845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
6855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
6865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
6885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(MD5withRSA_Vector2Signature));
6895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
6905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA1withRSA_Key_InitSignThenInitVerify_Success() throws Exception {
6925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
6935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
6945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
6955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
6965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
6975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
6985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
6995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(privKeySpec);
7005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
7025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // Start a signing operation
7045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
7055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
7065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // Switch to verify
7085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
7095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
7105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must match expected signature",
7125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA1withRSA_Vector1Signature));
7135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
7145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA1withRSA_Key_TwoMessages_Success() throws Exception {
7165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
7175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
7185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
7195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
7215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
7225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
7245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("First signature must match expected signature",
7255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA1withRSA_Vector1Signature));
7265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
7285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Second signature must match expected signature",
7295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                sig.verify(SHA1withRSA_Vector2Signature));
7305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
7315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA1withRSA_Key_WrongExpectedSignature_Failure() throws Exception {
7335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
7345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(RSA_2048_modulus, RSA_2048_publicExponent);
7355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(keySpec);
7365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
7385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
7395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
7405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertFalse("Signature should fail to verify", sig.verify(SHA1withRSA_Vector2Signature));
7425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
7435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withRSA_CrtKeyWithPublicExponent_Success() throws Exception {
7455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
7465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(RSA_2048_modulus,
7475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent, RSA_2048_privateExponent, null, null, null, null, null);
7485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // The RI fails on this key which is totally unreasonable.
7505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        final PrivateKey privKey;
7515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
7525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            privKey = kf.generatePrivate(keySpec);
7535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        } catch (NullPointerException e) {
7545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            if (StandardNames.IS_RI) {
7555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                return;
7565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            } else {
7575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                fail("Private key should be created");
7585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                return;
7595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            }
7605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
7615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
7635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
7645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
7655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
7675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
7685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
7695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, SHA1withRSA_Vector1Signature));
7705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
7725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
7735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
7745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
7755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
7765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
7775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
7785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withRSA_CrtKey_NoPrivateExponent_Failure() throws Exception {
7805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
7815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(RSA_2048_modulus,
7825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent, null, RSA_2048_primeP, RSA_2048_primeQ, null, null, null);
7835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // Failing on this key early is okay.
7855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        final PrivateKey privKey;
7865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
7875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            privKey = kf.generatePrivate(keySpec);
7885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        } catch (NullPointerException e) {
7895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            return;
790746a236e2be5dee62c482e27f4c682496d071d8bKenny Root        } catch (InvalidKeySpecException e) {
791746a236e2be5dee62c482e27f4c682496d071d8bKenny Root            return;
7925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
7935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
7955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
7965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
7975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            sig.initSign(privKey);
7985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            fail("Should throw error when private exponent is not available");
7990a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (InvalidKeyException expected) {
8005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
8015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
8025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withRSA_CrtKey_NoModulus_Failure() throws Exception {
8045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
8055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateCrtKeySpec keySpec = new RSAPrivateCrtKeySpec(null, RSA_2048_publicExponent,
8065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent, RSA_2048_primeP, RSA_2048_primeQ, null, null, null);
8075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // Failing on this key early is okay.
8095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        final PrivateKey privKey;
8105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
8115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            privKey = kf.generatePrivate(keySpec);
8125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        } catch (NullPointerException e) {
8135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            return;
814746a236e2be5dee62c482e27f4c682496d071d8bKenny Root        } catch (InvalidKeySpecException e) {
815746a236e2be5dee62c482e27f4c682496d071d8bKenny Root            return;
8165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
8175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
8195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
8215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            sig.initSign(privKey);
8225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            fail("Should throw error when modulus is not available");
8230a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (InvalidKeyException expected) {
8245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
8255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
8265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withRSA_Key_EmptyKey_Failure() throws Exception {
8285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
8295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(null, null);
8305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        // Failing on this key early is okay.
8325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        final PrivateKey privKey;
8335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
8345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            privKey = kf.generatePrivate(keySpec);
8355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        } catch (NullPointerException e) {
8365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            return;
837746a236e2be5dee62c482e27f4c682496d071d8bKenny Root        } catch (InvalidKeySpecException e) {
838746a236e2be5dee62c482e27f4c682496d071d8bKenny Root            return;
8395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
8405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
8425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        try {
8445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            sig.initSign(privKey);
8455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root            fail("Should throw error when key is empty");
8460a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (InvalidKeyException expected) {
8475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        }
8485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
8495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withRSA_Key_Success() throws Exception {
8515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
8525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
8535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
8545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
8555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withRSA");
8575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
8585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
8595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
8615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
8625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
8635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, SHA1withRSA_Vector1Signature));
8645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
8665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
8675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
8685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
8695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector1Data);
8705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
8715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
8725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA256withRSA_Key_Success() throws Exception {
8745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
8755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
8765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
8775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        final PrivateKey privKey = kf.generatePrivate(keySpec);
8795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA256withRSA");
8815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
8825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
8835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
8855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
8865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
8875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, SHA256withRSA_Vector2Signature));
8885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
8905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
8915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
8925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
8935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
8945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
8955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
8965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
8975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA384withRSA_Key_Success() throws Exception {
8985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
8995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
9005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
9015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
9025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA384withRSA");
9045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
9055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
9085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
9095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
9105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, SHA384withRSA_Vector2Signature));
9115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
9135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
9145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
9155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
9165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
9185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
9195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA512withRSA_Key_Success() throws Exception {
9215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
9225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
9235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
9245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
9255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA512withRSA");
9275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
9285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
9315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
9325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
9335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, SHA512withRSA_Vector2Signature));
9345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
9365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
9375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
9385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
9395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
9415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
9425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_MD5withRSA_Key_Success() throws Exception {
9445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
9455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
9465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_privateExponent);
9475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
9485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("MD5withRSA");
9505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
9515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
9545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
9555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature should match expected",
9565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                Arrays.equals(signature, MD5withRSA_Vector2Signature));
9575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
9595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root                RSA_2048_publicExponent);
9605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
9615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
9625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
9635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
9645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
9655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
9667501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testSign_NONEwithRSA_Key_Success() throws Exception {
9677501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
9687501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
9697501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_privateExponent);
9707501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
9717501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9727501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
9737501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initSign(privKey);
9747501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(Vector1Data);
9757501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9767501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        byte[] signature = sig.sign();
9777501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertNotNull("Signature must not be null", signature);
9787501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertTrue("Signature should match expected",
9797501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                Arrays.equals(signature, NONEwithRSA_Vector1Signature));
9807501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9817501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
9827501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
9837501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
9847501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
9857501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(Vector1Data);
9867501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
9877501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
9887501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9897501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testVerify_NONEwithRSA_Key_WrongSignature_Failure() throws Exception {
9907501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
9917501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9927501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
9937501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
9947501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
9957501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
9967501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
9977501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
9987501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(Vector1Data);
9997501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertFalse("Invalid signature must not verify", sig.verify("Invalid".getBytes()));
10007501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
10017501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10027501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testSign_NONEwithRSA_Key_DataTooLarge_Failure() throws Exception {
10037501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
10047501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
10057501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_privateExponent);
10067501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
10077501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10087501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
10097501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initSign(privKey);
10107501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10117501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        final int oneTooBig = RSA_2048_modulus.bitLength() - 10;
10127501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        for (int i = 0; i < oneTooBig; i++) {
10137501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.update((byte) i);
10147501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10157501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10167501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        try {
10177501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.sign();
10187501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            fail("Should throw exception when data is too large");
10190a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (SignatureException expected) {
10207501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10217501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
10227501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10237501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testSign_NONEwithRSA_Key_DataTooLarge_SingleByte_Failure() throws Exception {
10247501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
10257501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(RSA_2048_modulus,
10267501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_privateExponent);
10277501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
10287501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10297501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
10307501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initSign(privKey);
10317501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10327501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        // This should make it two bytes too big.
10337501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        final int oneTooBig = RSA_2048_modulus.bitLength() - 10;
10347501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        for (int i = 0; i < oneTooBig; i++) {
10357501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.update((byte) i);
10367501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10377501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10387501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        try {
10397501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.sign();
10407501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            fail("Should throw exception when data is too large");
10410a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (SignatureException expected) {
10427501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10437501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
10447501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10457501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testVerify_NONEwithRSA_Key_DataTooLarge_Failure() throws Exception {
10467501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
10477501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10487501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
10497501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
10507501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
10517501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10527501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
10537501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
10547501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10557501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        // This should make it one bytes too big.
10567501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        final int oneTooBig = RSA_2048_modulus.bitLength() + 1;
10577501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        final byte[] vector = new byte[oneTooBig];
10587501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        for (int i = 0; i < oneTooBig; i++) {
10597501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            vector[i] = (byte) Vector1Data[i % Vector1Data.length];
10607501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10617501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(vector);
10627501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10637501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertFalse("Should not verify when signature is too large",
10647501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                sig.verify(NONEwithRSA_Vector1Signature));
10657501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
10667501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10677501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testVerify_NONEwithRSA_Key_DataTooLarge_SingleByte_Failure() throws Exception {
10687501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
10697501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10707501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
10717501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
10727501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
10737501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10747501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
10757501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
10767501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10777501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        // This should make it twice as big as it should be.
10787501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        final int tooBig = RSA_2048_modulus.bitLength() * 2;
10797501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        for (int i = 0; i < tooBig; i++) {
10807501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.update((byte) Vector1Data[i % Vector1Data.length]);
10817501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
10827501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10837501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertFalse("Should not verify when signature is too large",
10847501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                sig.verify(NONEwithRSA_Vector1Signature));
10857501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
10867501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10877501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testVerify_NONEwithRSA_Key_SignatureTooSmall_Failure() throws Exception {
10887501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
10897501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10907501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
10917501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
10927501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
10937501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10947501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
10957501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
10967501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(Vector1Data);
10977501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
10987501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        assertFalse("Invalid signature should not verify", sig.verify("Invalid sig".getBytes()));
10997501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
11007501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11017501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    public void testVerify_NONEwithRSA_Key_SignatureTooLarge_Failure() throws Exception {
11027501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        KeyFactory kf = KeyFactory.getInstance("RSA");
11037501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11047501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(RSA_2048_modulus,
11057501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                RSA_2048_publicExponent);
11067501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
11077501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11087501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        Signature sig = Signature.getInstance("NONEwithRSA");
11097501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.initVerify(pubKey);
11107501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        sig.update(Vector1Data);
11117501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11127501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        byte[] invalidSignature = new byte[NONEwithRSA_Vector1Signature.length * 2];
11137501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature, 0,
11147501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                NONEwithRSA_Vector1Signature.length);
11157501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        System.arraycopy(NONEwithRSA_Vector1Signature, 0, invalidSignature,
11167501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root                NONEwithRSA_Vector1Signature.length, NONEwithRSA_Vector1Signature.length);
11177501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11187501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        try {
11197501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            sig.verify(invalidSignature);
11207501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root            fail("Should throw exception when signature is too large");
11210a156e0126e8015f2791e9a7dd48bbdaeae0c335Brian Carlstrom        } catch (SignatureException expected) {
11227501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root        }
11237501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root    }
11247501e29e0182accf28cc317870a3bbe1e25f4bfaKenny Root
11255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    /*
11265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * These tests were generated with this DSA private key:
11275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     *
11285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * -----BEGIN DSA PRIVATE KEY-----
11295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * MIIBugIBAAKBgQCeYcKJ73epThNnZB8JAf4kE1Pgt5CoTnb+iYJ/esU8TgwgVTCV
11305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * QoXhQH0njwcN6NyZ77MHlDTWfP+cvmnT60Q3UO9J+OJb2NEQhJfq46UcwE5pynA9
11315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * eLkW5f5hXYpasyxhtgE70AF8Mo3h82kOi1jGzwCU+EkqS+raAP9L0L5AIwIVAL/u
11325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * qg8SNFBy+GAT2PFBARClL1dfAoGAd9R6EsyBfn7rOvvmhm1aEB2tqU+5A10hGuQw
11335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * lXWOzV7RvQpF7uf3a2UCYNAurz28B90rjjPAk4DZK6dxV3a8jrng1/QjjUEal08s
11345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * G9VLZuj60lANF6s0MT2kiNiOqKduFwO3D2h8ZHuSuGPkmmcYgSfUCxNI031O9qiP
11355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * VhctCFECgYAz7i1DhjRGUkCdYQd5tVaI42lhXOV71MTYPbuFOIxTL/hny7Z0PZWR
11365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * A1blmYE6vrArDEhzpmRvDJZSIMzMfJjUIGu1KO73zpo9siK0xY0/sw5r3QC9txP2
11375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * 2Mv3BUIl5TLrs9outQJ0VMwldY2fElgCLWcSVkH44qZwWir1cq+cIwIUEGPDardb
11385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * pNvWlWgTDD6a6ZTby+M=
11395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * -----END DSA PRIVATE KEY-----
11405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     *
11415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     */
11425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
11435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger DSA_priv = new BigInteger(new byte[] {
11445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x10, (byte) 0x63, (byte) 0xc3, (byte) 0x6a, (byte) 0xb7, (byte) 0x5b, (byte) 0xa4, (byte) 0xdb,
11455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd6, (byte) 0x95, (byte) 0x68, (byte) 0x13, (byte) 0x0c, (byte) 0x3e, (byte) 0x9a, (byte) 0xe9,
11465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x94, (byte) 0xdb, (byte) 0xcb, (byte) 0xe3,
11475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
11485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
11495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger DSA_pub = new BigInteger(new byte[] {
11505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x33, (byte) 0xee, (byte) 0x2d, (byte) 0x43, (byte) 0x86, (byte) 0x34, (byte) 0x46, (byte) 0x52,
11515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x40, (byte) 0x9d, (byte) 0x61, (byte) 0x07, (byte) 0x79, (byte) 0xb5, (byte) 0x56, (byte) 0x88,
11525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe3, (byte) 0x69, (byte) 0x61, (byte) 0x5c, (byte) 0xe5, (byte) 0x7b, (byte) 0xd4, (byte) 0xc4,
11535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd8, (byte) 0x3d, (byte) 0xbb, (byte) 0x85, (byte) 0x38, (byte) 0x8c, (byte) 0x53, (byte) 0x2f,
11545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf8, (byte) 0x67, (byte) 0xcb, (byte) 0xb6, (byte) 0x74, (byte) 0x3d, (byte) 0x95, (byte) 0x91,
11555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x03, (byte) 0x56, (byte) 0xe5, (byte) 0x99, (byte) 0x81, (byte) 0x3a, (byte) 0xbe, (byte) 0xb0,
11565b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2b, (byte) 0x0c, (byte) 0x48, (byte) 0x73, (byte) 0xa6, (byte) 0x64, (byte) 0x6f, (byte) 0x0c,
11575b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x96, (byte) 0x52, (byte) 0x20, (byte) 0xcc, (byte) 0xcc, (byte) 0x7c, (byte) 0x98, (byte) 0xd4,
11585b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x20, (byte) 0x6b, (byte) 0xb5, (byte) 0x28, (byte) 0xee, (byte) 0xf7, (byte) 0xce, (byte) 0x9a,
11595b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3d, (byte) 0xb2, (byte) 0x22, (byte) 0xb4, (byte) 0xc5, (byte) 0x8d, (byte) 0x3f, (byte) 0xb3,
11605b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x0e, (byte) 0x6b, (byte) 0xdd, (byte) 0x00, (byte) 0xbd, (byte) 0xb7, (byte) 0x13, (byte) 0xf6,
11615b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd8, (byte) 0xcb, (byte) 0xf7, (byte) 0x05, (byte) 0x42, (byte) 0x25, (byte) 0xe5, (byte) 0x32,
11625b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xeb, (byte) 0xb3, (byte) 0xda, (byte) 0x2e, (byte) 0xb5, (byte) 0x02, (byte) 0x74, (byte) 0x54,
11635b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xcc, (byte) 0x25, (byte) 0x75, (byte) 0x8d, (byte) 0x9f, (byte) 0x12, (byte) 0x58, (byte) 0x02,
11645b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2d, (byte) 0x67, (byte) 0x12, (byte) 0x56, (byte) 0x41, (byte) 0xf8, (byte) 0xe2, (byte) 0xa6,
11655b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x70, (byte) 0x5a, (byte) 0x2a, (byte) 0xf5, (byte) 0x72, (byte) 0xaf, (byte) 0x9c, (byte) 0x23,
11665b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
11675b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
11685b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger DSA_P = new BigInteger(new byte[] {
11695b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x00, (byte) 0x9e, (byte) 0x61, (byte) 0xc2, (byte) 0x89, (byte) 0xef, (byte) 0x77, (byte) 0xa9,
11705b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4e, (byte) 0x13, (byte) 0x67, (byte) 0x64, (byte) 0x1f, (byte) 0x09, (byte) 0x01, (byte) 0xfe,
11715b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x24, (byte) 0x13, (byte) 0x53, (byte) 0xe0, (byte) 0xb7, (byte) 0x90, (byte) 0xa8, (byte) 0x4e,
11725b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x76, (byte) 0xfe, (byte) 0x89, (byte) 0x82, (byte) 0x7f, (byte) 0x7a, (byte) 0xc5, (byte) 0x3c,
11735b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x4e, (byte) 0x0c, (byte) 0x20, (byte) 0x55, (byte) 0x30, (byte) 0x95, (byte) 0x42, (byte) 0x85,
11745b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xe1, (byte) 0x40, (byte) 0x7d, (byte) 0x27, (byte) 0x8f, (byte) 0x07, (byte) 0x0d, (byte) 0xe8,
11755b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdc, (byte) 0x99, (byte) 0xef, (byte) 0xb3, (byte) 0x07, (byte) 0x94, (byte) 0x34, (byte) 0xd6,
11765b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x7c, (byte) 0xff, (byte) 0x9c, (byte) 0xbe, (byte) 0x69, (byte) 0xd3, (byte) 0xeb, (byte) 0x44,
11775b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x37, (byte) 0x50, (byte) 0xef, (byte) 0x49, (byte) 0xf8, (byte) 0xe2, (byte) 0x5b, (byte) 0xd8,
11785b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd1, (byte) 0x10, (byte) 0x84, (byte) 0x97, (byte) 0xea, (byte) 0xe3, (byte) 0xa5, (byte) 0x1c,
11795b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc0, (byte) 0x4e, (byte) 0x69, (byte) 0xca, (byte) 0x70, (byte) 0x3d, (byte) 0x78, (byte) 0xb9,
11805b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x16, (byte) 0xe5, (byte) 0xfe, (byte) 0x61, (byte) 0x5d, (byte) 0x8a, (byte) 0x5a, (byte) 0xb3,
11815b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2c, (byte) 0x61, (byte) 0xb6, (byte) 0x01, (byte) 0x3b, (byte) 0xd0, (byte) 0x01, (byte) 0x7c,
11825b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x32, (byte) 0x8d, (byte) 0xe1, (byte) 0xf3, (byte) 0x69, (byte) 0x0e, (byte) 0x8b, (byte) 0x58,
11835b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xc6, (byte) 0xcf, (byte) 0x00, (byte) 0x94, (byte) 0xf8, (byte) 0x49, (byte) 0x2a, (byte) 0x4b,
11845b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xea, (byte) 0xda, (byte) 0x00, (byte) 0xff, (byte) 0x4b, (byte) 0xd0, (byte) 0xbe, (byte) 0x40,
11855b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x23,
11865b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
11875b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
11885b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger DSA_Q = new BigInteger(new byte[] {
11895b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x00, (byte) 0xbf, (byte) 0xee, (byte) 0xaa, (byte) 0x0f, (byte) 0x12, (byte) 0x34, (byte) 0x50,
11905b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x72, (byte) 0xf8, (byte) 0x60, (byte) 0x13, (byte) 0xd8, (byte) 0xf1, (byte) 0x41, (byte) 0x01,
11915b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x10, (byte) 0xa5, (byte) 0x2f, (byte) 0x57, (byte) 0x5f,
11925b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
11935b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
11945b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    private static final BigInteger DSA_G = new BigInteger(new byte[] {
11955b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x77, (byte) 0xd4, (byte) 0x7a, (byte) 0x12, (byte) 0xcc, (byte) 0x81, (byte) 0x7e, (byte) 0x7e,
11965b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xeb, (byte) 0x3a, (byte) 0xfb, (byte) 0xe6, (byte) 0x86, (byte) 0x6d, (byte) 0x5a, (byte) 0x10,
11975b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1d, (byte) 0xad, (byte) 0xa9, (byte) 0x4f, (byte) 0xb9, (byte) 0x03, (byte) 0x5d, (byte) 0x21,
11985b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x1a, (byte) 0xe4, (byte) 0x30, (byte) 0x95, (byte) 0x75, (byte) 0x8e, (byte) 0xcd, (byte) 0x5e,
11995b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd1, (byte) 0xbd, (byte) 0x0a, (byte) 0x45, (byte) 0xee, (byte) 0xe7, (byte) 0xf7, (byte) 0x6b,
12005b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x65, (byte) 0x02, (byte) 0x60, (byte) 0xd0, (byte) 0x2e, (byte) 0xaf, (byte) 0x3d, (byte) 0xbc,
12015b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x07, (byte) 0xdd, (byte) 0x2b, (byte) 0x8e, (byte) 0x33, (byte) 0xc0, (byte) 0x93, (byte) 0x80,
12025b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xd9, (byte) 0x2b, (byte) 0xa7, (byte) 0x71, (byte) 0x57, (byte) 0x76, (byte) 0xbc, (byte) 0x8e,
12035b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xb9, (byte) 0xe0, (byte) 0xd7, (byte) 0xf4, (byte) 0x23, (byte) 0x8d, (byte) 0x41, (byte) 0x1a,
12045b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x97, (byte) 0x4f, (byte) 0x2c, (byte) 0x1b, (byte) 0xd5, (byte) 0x4b, (byte) 0x66, (byte) 0xe8,
12055b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xfa, (byte) 0xd2, (byte) 0x50, (byte) 0x0d, (byte) 0x17, (byte) 0xab, (byte) 0x34, (byte) 0x31,
12065b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x3d, (byte) 0xa4, (byte) 0x88, (byte) 0xd8, (byte) 0x8e, (byte) 0xa8, (byte) 0xa7, (byte) 0x6e,
12075b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x17, (byte) 0x03, (byte) 0xb7, (byte) 0x0f, (byte) 0x68, (byte) 0x7c, (byte) 0x64, (byte) 0x7b,
12085b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x92, (byte) 0xb8, (byte) 0x63, (byte) 0xe4, (byte) 0x9a, (byte) 0x67, (byte) 0x18, (byte) 0x81,
12095b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x27, (byte) 0xd4, (byte) 0x0b, (byte) 0x13, (byte) 0x48, (byte) 0xd3, (byte) 0x7d, (byte) 0x4e,
12105b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xf6, (byte) 0xa8, (byte) 0x8f, (byte) 0x56, (byte) 0x17, (byte) 0x2d, (byte) 0x08, (byte) 0x51,
12115b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    });
12125b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12135b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    /**
12145b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * A possible signature using SHA1withDSA of Vector2Data. Note that DSS is
12155b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * randomized, so this won't be the exact signature you'll get out of
12165b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     * another signing operation unless you use a fixed RNG.
12175b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root     */
12185b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public static final byte[] SHA1withDSA_Vector2Signature = new byte[] {
12195b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x30, (byte) 0x2d, (byte) 0x02, (byte) 0x15, (byte) 0x00, (byte) 0x88, (byte) 0xef, (byte) 0xac,
12205b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x2b, (byte) 0x8b, (byte) 0xe2, (byte) 0x61, (byte) 0xc6, (byte) 0x2b, (byte) 0xea, (byte) 0xd5,
12215b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x96, (byte) 0xbc, (byte) 0xb0, (byte) 0xa1, (byte) 0x30, (byte) 0x0c, (byte) 0x1f, (byte) 0xed,
12225b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x11, (byte) 0x02, (byte) 0x14, (byte) 0x15, (byte) 0xc4, (byte) 0xfc, (byte) 0x82, (byte) 0x6f,
12235b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0x17, (byte) 0xdc, (byte) 0x87, (byte) 0x82, (byte) 0x75, (byte) 0x23, (byte) 0xd4, (byte) 0x58,
12245b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        (byte) 0xdc, (byte) 0x73, (byte) 0x3d, (byte) 0xf3, (byte) 0x51, (byte) 0xc0, (byte) 0x57,
12255b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    };
12265b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12275b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testSign_SHA1withDSA_Key_Success() throws Exception {
12285b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("DSA");
12295b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        DSAPrivateKeySpec keySpec = new DSAPrivateKeySpec(DSA_priv, DSA_P, DSA_Q, DSA_G);
12305b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PrivateKey privKey = kf.generatePrivate(keySpec);
12315b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12325b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withDSA");
12335b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initSign(privKey);
12345b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
12355b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12365b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        byte[] signature = sig.sign();
12375b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertNotNull("Signature must not be null", signature);
12385b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12395b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(DSA_pub, DSA_P, DSA_Q, DSA_G);
12405b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
12415b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
12425b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
12435b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(signature));
12445b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
12455b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12465b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    public void testVerify_SHA1withDSA_Key_Success() throws Exception {
12475b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        KeyFactory kf = KeyFactory.getInstance("DSA");
12485b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(DSA_pub, DSA_P, DSA_Q, DSA_G);
12495b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        PublicKey pubKey = kf.generatePublic(pubKeySpec);
12505b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root
12515b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        Signature sig = Signature.getInstance("SHA1withDSA");
12525b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.initVerify(pubKey);
12535b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        sig.update(Vector2Data);
12545b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root        assertTrue("Signature must verify correctly", sig.verify(SHA1withDSA_Vector2Signature));
12555b57eb538f8da8e97cf88a310d75d14dfc91624cKenny Root    }
1256eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom
1257eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    // NetscapeCertRequest looks up Signature algorithms by OID from
1258eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    // BC but BC version 1.47 had registration bugs and MD5withRSA was
1259eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    // overlooked.  http://b/7453821
1260eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    public void testGetInstanceFromOID() throws Exception {
1261eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.4");  // MD5withRSA
1262eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.5");  // SHA1withRSA
1263eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.3.14.3.2.29");         // SHA1withRSA
1264eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.11"); // SHA256withRSA
1265eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.12"); // SHA384withRSA
1266eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.113549.1.1.13"); // SHA512withRSA
1267eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertBouncyCastleSignatureFromOID("1.2.840.10040.4.3");     // SHA1withDSA
1268eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    }
1269eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom
1270eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    private void assertBouncyCastleSignatureFromOID(String oid) throws Exception {
1271eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        Signature signature = Signature.getInstance(oid, "BC");
1272eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertNotNull(oid, signature);
1273eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom        assertEquals(oid, signature.getAlgorithm());
1274eef7e9357c272a9154f007e8bee2a09eed66d101Brian Carlstrom    }
127557f2cc03ff2cf5d2f6413c5410680b4908d7301dBrian Carlstrom}
1276