Search in sources :

Example 21 with RSAPrivateCrtKey

use of java.security.interfaces.RSAPrivateCrtKey in project jdk8u_jdk by JetBrains.

the class SmallPrimeExponentP method main.

public static void main(String[] argv) throws Exception {
    String osName = System.getProperty("os.name");
    if (!osName.startsWith("Windows")) {
        System.out.println("Not windows");
        return;
    }
    KeyStore ks = KeyStore.getInstance("Windows-MY");
    ks.load(null, null);
    CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
    ckg.setRandom(new SecureRandom());
    boolean see63 = false, see65 = false;
    while (!see63 || !see65) {
        ckg.generate(1024);
        RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey();
        int len = k.getPrimeExponentP().toByteArray().length;
        if (len == 63 || len == 65) {
            if (len == 63) {
                if (see63)
                    continue;
                else
                    see63 = true;
            }
            if (len == 65) {
                if (see65)
                    continue;
                else
                    see65 = true;
            }
            System.err.print(len);
            ks.setKeyEntry("anything", k, null, new X509Certificate[] { ckg.getSelfCertificate(new X500Name("CN=Me"), 1000) });
        }
        System.err.print('.');
    }
    ks.store(null, null);
}
Also used : RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) CertAndKeyGen(sun.security.tools.keytool.CertAndKeyGen) SecureRandom(java.security.SecureRandom) X500Name(sun.security.x509.X500Name) KeyStore(java.security.KeyStore)

Aggregations

RSAPrivateCrtKey (java.security.interfaces.RSAPrivateCrtKey)21 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)11 RSAPublicKey (java.security.interfaces.RSAPublicKey)7 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)7 InvalidKeyException (java.security.InvalidKeyException)6 PrivateKey (java.security.PrivateKey)6 PublicKey (java.security.PublicKey)6 RSAPrivateCrtKeySpec (java.security.spec.RSAPrivateCrtKeySpec)6 RSAPublicKeySpec (java.security.spec.RSAPublicKeySpec)6 BigInteger (java.math.BigInteger)5 KeyPair (java.security.KeyPair)5 RSAPrivateKeySpec (java.security.spec.RSAPrivateKeySpec)5 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)4 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)4 KeyFactory (java.security.KeyFactory)3 DSAPrivateKey (java.security.interfaces.DSAPrivateKey)3 KeyPairGenerator (java.security.KeyPairGenerator)2 KeyStore (java.security.KeyStore)2 X509Certificate (java.security.cert.X509Certificate)2 DSAParams (java.security.interfaces.DSAParams)2