Java 8 RSAPrivateCrtKeySpec - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 RSAPrivateCrtKeySpec class.

This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
    public OpenSSLRSAPrivateCrtKey(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        super(init(rsaKeySpec));
    } 
 
    private static OpenSSLKey init(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        BigInteger modulus = rsaKeySpec.getModulus();
        BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeySpecException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeySpecException("privateExponent == null");
        } 
 
        try { 
            /* 
             * OpenSSL uses the public modulus to do RSA blinding. If 
             * the public modulus is not available, the call to 
             * EVP_PKEY_new_RSA will turn off blinding for this key 
             * instance. 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    @Override 
    protected PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException {
        if (keySpec instanceof RSAPrivateCrtKeySpec) {
            RSAPrivateCrtKeySpec rsaKeySpec = (RSAPrivateCrtKeySpec) keySpec;
 
            return new OpenSSLRSAPrivateCrtKey(rsaKeySpec);
        } else if (keySpec instanceof RSAPrivateKeySpec) {
            RSAPrivateKeySpec rsaKeySpec = (RSAPrivateKeySpec) keySpec;
 
            return new OpenSSLRSAPrivateKey(rsaKeySpec);
        } else if (keySpec instanceof PKCS8EncodedKeySpec) {
            PKCS8EncodedKeySpec pkcs8KeySpec = (PKCS8EncodedKeySpec) keySpec;
 
            try { 
                final OpenSSLKey key = new OpenSSLKey(
                        NativeCrypto.d2i_PKCS8_PRIV_KEY_INFO(pkcs8KeySpec.getEncoded()));
                return OpenSSLRSAPrivateKey.getInstance(key);
            } catch (Exception e) {
                throw new InvalidKeySpecException(e);
            } 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
    public OpenSSLRSAPrivateCrtKey(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        super(init(rsaKeySpec));
    } 
 
    private static OpenSSLKey init(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        BigInteger modulus = rsaKeySpec.getModulus();
        BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeySpecException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeySpecException("privateExponent == null");
        } 
 
        try { 
            /* 
             * OpenSSL uses the public modulus to do RSA blinding. If 
             * the public modulus is not available, the call to 
             * EVP_PKEY_new_RSA will turn off blinding for this key 
             * instance. 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
 
    public static void main(String[] args) throws Exception {
 
        // Create an RSA Private Key from the CRT information 
        RSAPrivateCrtKeySpec rsaCrtSpec =
            new RSAPrivateCrtKeySpec(new BigInteger(1, modulus),
                                     new BigInteger(1, pubExpo),
                                     new BigInteger(1, priExpo),
                                     new BigInteger(1, primeP),
                                     new BigInteger(1, primeQ),
                                     new BigInteger(1, expoP),
                                     new BigInteger(1, expoQ),
                                     new BigInteger(1, coeff));
 
        // Create an RSA private key from the CRT specification 
        KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
        RSAPrivateCrtKey rsaPriKey =
            (RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);
 
        // test resulting key against original specification 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
 
    public static void main(String[] args) throws Exception {
 
        // Create an RSA Private Key from the CRT information 
        RSAPrivateCrtKeySpec rsaCrtSpec =
            new RSAPrivateCrtKeySpec(new BigInteger(1, modulus),
                                     new BigInteger(1, pubExpo),
                                     new BigInteger(1, priExpo),
                                     new BigInteger(1, primeP),
                                     new BigInteger(1, primeQ),
                                     new BigInteger(1, expoP),
                                     new BigInteger(1, expoQ),
                                     new BigInteger(1, coeff));
 
        // Create an RSA private key from the CRT specification 
        KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
        RSAPrivateCrtKey rsaPriKey =
            (RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);
 
        // test resulting key against original specification 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
    public OpenSSLRSAPrivateCrtKey(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        super(init(rsaKeySpec));
    } 
 
    private static OpenSSLKey init(RSAPrivateCrtKeySpec rsaKeySpec) throws InvalidKeySpecException {
        BigInteger modulus = rsaKeySpec.getModulus();
        BigInteger privateExponent = rsaKeySpec.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeySpecException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeySpecException("privateExponent == null");
        } 
 
        try { 
            /* 
             * OpenSSL uses the public modulus to do RSA blinding. If 
             * the public modulus is not available, the call to 
             * EVP_PKEY_new_RSA will turn off blinding for this key 
             * instance. 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
 
    public static void main(String[] args) throws Exception {
 
        // Create an RSA Private Key from the CRT information 
        RSAPrivateCrtKeySpec rsaCrtSpec =
            new RSAPrivateCrtKeySpec(new BigInteger(1, modulus),
                                     new BigInteger(1, pubExpo),
                                     new BigInteger(1, priExpo),
                                     new BigInteger(1, primeP),
                                     new BigInteger(1, primeQ),
                                     new BigInteger(1, expoP),
                                     new BigInteger(1, expoQ),
                                     new BigInteger(1, coeff));
 
        // Create an RSA private key from the CRT specification 
        KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
        RSAPrivateCrtKey rsaPriKey =
            (RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);
 
        // test resulting key against original specification 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
 
    public static void main(String[] args) throws Exception {
 
        // Create an RSA Private Key from the CRT information 
        RSAPrivateCrtKeySpec rsaCrtSpec =
            new RSAPrivateCrtKeySpec(new BigInteger(1, modulus),
                                     new BigInteger(1, pubExpo),
                                     new BigInteger(1, priExpo),
                                     new BigInteger(1, primeP),
                                     new BigInteger(1, primeQ),
                                     new BigInteger(1, expoP),
                                     new BigInteger(1, expoQ),
                                     new BigInteger(1, coeff));
 
        // Create an RSA private key from the CRT specification 
        KeyFactory kf = KeyFactory.getInstance("RSA", "SunRsaSign");
        RSAPrivateCrtKey rsaPriKey =
            (RSAPrivateCrtKey) kf.generatePrivate(rsaCrtSpec);
 
        // test resulting key against original specification 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getPublicExponent, getModulus
 
   /** 
    * @return true if the keypairs match 
    */ 
   public static boolean privateKeyMatchesPublicKey(RSAPrivateCrtKeySpec privateKey, RSAPublicKeySpec publicKey) {
      return privateKey.getPublicExponent().equals(publicKey.getPublicExponent())
               && privateKey.getModulus().equals(publicKey.getModulus());
   } 
 
   /** 
    * @return true if the keypair has the same fingerprint as supplied 
    */ 
   public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) {
      return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint);
   } 
 
   /** 
    * @param privateKeyPEM 
    *           RSA private key in PEM format 
    * @param fingerprint 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getCrtCoefficient
    /** 
     * Test for <code>getCrtCoefficient()</code> method<br> 
     * Assertion: returns crt coefficient 
     */ 
    public final void testGetCrtCoefficient() { 
        RSAPrivateCrtKeySpec ks = new RSAPrivateCrtKeySpec(
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.ONE,
                BigInteger.valueOf(5L));
        assertTrue(BigInteger.valueOf(5L).equals(ks.getCrtCoefficient()));
    } 
 
    /** 
     * Test for <code>getPrimeExponentP()</code> method<br> 
     * Assertion: returns prime exponent P 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 RSAPrivateCrtKeySpec Methods: