Java 8 RSAPrivateKey - 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 RSAPrivateKey class.

This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
		} else if (format != null && format.equalsIgnoreCase("PKCS#1")
				&& key instanceof RSAPrivateCrtKey) {
			// this condition will rarely be true 
			RSAPrivateCrtKey pKey = (RSAPrivateCrtKey) key;
			RSAPrivateKeyStructure st = new RSAPrivateKeyStructure(pKey
					.getModulus(), pKey.getPublicExponent(), pKey
					.getPrivateExponent(), pKey.getPrimeP(), pKey.getPrimeQ(),
					pKey.getPrimeExponentP(), pKey.getPrimeExponentQ(), pKey
							.getCrtCoefficient());
			ASN1Primitive ob = st.toASN1Primitive();
 
			try { 
				return BouncyCastleUtil.toByteArray(ob);
			} catch (IOException e) {
				// that should never happen 
				return new byte[0]; 
			} 
		} else { 
			return new byte[0]; 
		} 
7
CodeRank
This code example shows how to use the following methods:getPrimeP, getPrimeQ, getPrivateExponent
 
        if (privateKey instanceof  RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey rsK = (RSAPrivateCrtKey)privateKey;
 
            privateKeyDataPacket = new RSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ());
        } 
        else if (privateKey instanceof DSAPrivateKey)
        { 
            DSAPrivateKey dsK = (DSAPrivateKey)privateKey;
 
            privateKeyDataPacket = new DSASecretBCPGKey(dsK.getX());
        } 
        else if (privateKey instanceof  ElGamalPrivateKey)
        { 
            ElGamalPrivateKey esK = (ElGamalPrivateKey)privateKey;
 
            privateKeyDataPacket = new ElGamalSecretBCPGKey(esK.getX());
        } 
        else 
7
CodeRank
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
            throw new InvalidKeySpecException(e);
        } 
    } 
 
    static OpenSSLKey getInstance(RSAPrivateCrtKey rsaPrivateKey) throws InvalidKeyException {
        BigInteger modulus = rsaPrivateKey.getModulus();
        BigInteger privateExponent = rsaPrivateKey.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeyException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeyException("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
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
    { 
        if (key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeyParameters(k.getModulus(),
                k.getPublicExponent(), k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(), k.getPrimeExponentQ(), k.getCrtCoefficient());
        } 
        else 
        { 
            RSAPrivateKey k = key;
 
            return new RSAKeyParameters(true, k.getModulus(), k.getPrivateExponent());
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP, getPrimeQ
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
        else if (spec.isAssignableFrom(RSAPrivateCrtKeySpec.class) && key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeySpec(
                k.getModulus(), k.getPublicExponent(),
                k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(),
                k.getPrimeExponentP(), k.getPrimeExponentQ(),
                k.getCrtCoefficient());
        } 
 
        return super.engineGetKeySpec(key, spec);
    } 
 
    protected Key engineTranslateKey(
        Key key)
        throws InvalidKeyException 
    { 
        if (key instanceof RSAPublicKey)
7
CodeRank
This code example shows how to use the following methods:getModulus, getPrivateExponent
            } 
        } else if (key instanceof RSAPrivateKey) {
            RSAPrivateKey rsaKey = (RSAPrivateKey) key;
 
            if (RSAPrivateKeySpec.class.equals(keySpec)) {
                BigInteger modulus = rsaKey.getModulus();
                BigInteger privateExponent = rsaKey.getPrivateExponent();
                return (T) new RSAPrivateKeySpec(modulus, privateExponent);
            } else if (RSAPrivateCrtKeySpec.class.equals(keySpec)) {
                BigInteger modulus = rsaKey.getModulus();
                BigInteger privateExponent = rsaKey.getPrivateExponent();
                return (T) new RSAPrivateCrtKeySpec(modulus, null, privateExponent, null, null,
                        null, null, null); 
            } else if (PKCS8EncodedKeySpec.class.equals(keySpec)) {
                return (T) new PKCS8EncodedKeySpec(rsaKey.getEncoded());
            } else { 
                throw new InvalidKeySpecException(
                        "Must be RSAPrivateKeySpec or PKCS8EncodedKeySpec"); 
            } 
        } else { 
7
CodeRank
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
            throw new InvalidKeySpecException(e);
        } 
    } 
 
    static OpenSSLKey getInstance(RSAPrivateCrtKey rsaPrivateKey) throws InvalidKeyException {
        BigInteger modulus = rsaPrivateKey.getModulus();
        BigInteger privateExponent = rsaPrivateKey.getPrivateExponent();
 
        if (modulus == null) {
            throw new InvalidKeyException("modulus == null");
        } else if (privateExponent == null) {
            throw new InvalidKeyException("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
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP
    { 
        if (key instanceof RSAPrivateCrtKey)
        { 
            RSAPrivateCrtKey    k = (RSAPrivateCrtKey)key;
 
            return new RSAPrivateCrtKeyParameters(k.getModulus(),
                k.getPublicExponent(), k.getPrivateExponent(),
                k.getPrimeP(), k.getPrimeQ(), k.getPrimeExponentP(),                            k.getPrimeExponentQ(), k.getCrtCoefficient());
        } 
        else 
        { 
            RSAPrivateKey    k = key;
 
            return new RSAKeyParameters(true, k.getModulus(), k.getPrivateExponent());
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:getModulus, getCrtCoefficient, getPrimeExponentP, getPrimeExponentQ, getPrimeP

Related Java 8 RSAPrivateKey Questions & Answers:

See Code Examples for Java 8 RSAPrivateKey Methods: