Converting an Existing Key Object to a JCE Key Object

2-2 Oracle Fusion Middleware Reference for Oracle Security Developer Tools ■ the ability to use third-party providers as the cryptographic engine

2.2 JCE Keys

In OracleAS 11gR1, the higher level toolkits Oracle XML Security, Oracle Web Services Security, Oracle CMS, Oracle SMIME, Oracle XKMS have changed so that instead of taking Oracle cryptographic keys and certificates, they take standard JCE keys and certificates. Thus, APIs that were taking oracle.security.crypto.core.PublicKey now take a java.security.PublicKey. ■ oracle.security.crypto.core.PublicKey changed to java.security.PublicKey ■ oracle.security.crypto.core.PrivateKey changed to java.security.PrivateKey ■ oracle.security.crypto.core.SymmetricKey changed to javax.crypto.SecretKey

2.2.1 Converting an Existing Key Object to a JCE Key Object

If you are using a java.security.KeyStore to store your keys, you will directly get a java.security.PrivateKey object from it, so you do not need to do any conversion. However if you are using a oracle.security.crypto.cert.PKCS12 object to store your keys, you will get an oracle.security.crypto.core.PrivateKey from it, and then you need to convert to a java.security.PrivateKey object. Converting a Private Key from Oracle Security Developer Tools to JCE Object Conversion or PrivateKeys from OSDT - JCE { Example code to convert an RSAPrivateKey non CRT to JCE oracle.security.crypto.core.RSAPrivateKey osdtKey = null; RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec osdtKey.getModulus, osdtKey.getExponent; KeyFactory kf = KeyFactory.getInstanceRSA; RSAPrivateKey jceKey = RSAPrivateKeykf.generatePrivatekeySpec; } { Example code to convert an RSAPrivateKey CRT to JCE oracle.security.crypto.core.RSAPrivateKey osdtKey = null; RSAPrivateKeySpec keySpec = new RSAPrivateCrtKeySpec osdtKey.getModulus, osdtKey.getPublicExponent, osdtKey.getExponent, osdtKey.getPrimeP, osdtKey.getPrimeQ, osdtKey.getPrimeExponentP, osdtKey.getPrimeExponentQ, osdtKey.getCrtCoefficient; KeyFactory kf = KeyFactory.getInstanceRSA; Note: This discussion highlights changes in the Oracle Security Developer Tools in support of JCE. For fuller details of all the available cryptographic functions, see the API documentation. Migrating to the JCE Framework 2-3 RSAPrivateCrtKey jceKey = RSAPrivateCrtKeykf.generatePrivatekeySpec; } { Example code to convert a DSAPrivateKey to JCE oracle.security.crypto.core.DSAPrivateKey osdtKey = null; DSAPrivateKeySpec keySpec = new DSAPrivateKeySpec osdtKey.getX, osdtKey.getParams.getP, osdtKey.getParams.getQ, osdtKey.getParams.getG; KeyFactory kf = KeyFactory.getInstanceDSA; DSAPrivateKey jceKey = DSAPrivateKeykf.generatePrivatekeySpec; } { Example code to convert a DHPrivateKey to JCE oracle.security.crypto.core.DHPrivateKey osdtKey = null; Note q is assumed to be p-12 DHPrivateKeySpec keySpec = new DHPrivateKeySpec osdtKey.getX, osdtKey.getParams.getP, osdtKey.getParams.getG; KeyFactory kf = KeyFactory.getInstanceDiffieHelman; DHPrivateKey jceKey = DHPrivateKeykf.generatePrivatekeySpec; } Converting a Private Key from JCE Object to Oracle Security Developer Tools Conversion or Private Keys from JCE - OSDT { Example code to convert an RSAPrivateKey non CRT to OSDT RSAPrivateKey jceKey = null; oracle.security.crypto.core.RSAPrivateKey osdtKey = new oracle.security.crypto.core.RSAPrivateKey jceKey.getModulus, jceKey.getPrivateExponent; } { Example code to convert an RSAPrivateKey CRT to OSDT RSAPrivateCrtKey jceKey = null; oracle.security.crypto.core.RSAPrivateKey osdtKey = new oracle.security.crypto.core.RSAPrivateKey jceKey.getModulus, jceKey.getPrivateExponent, jceKey.getPublicExponent, jceKey.getPrimeP, jceKey.getPrimeQ, jceKey.getPrimeExponentP, jceKey.getPrimeExponentQ, jceKey.getCrtCoefficient; } 2-4 Oracle Fusion Middleware Reference for Oracle Security Developer Tools { Example code to convert an DSAPrivateKey to OSDT DSAPrivateKey jceKey = null; oracle.security.crypto.core.DSAPrivateKey osdtKey = new oracle.security.crypto.core.DSAPrivateKey jceKey.getX, new oracle.security.crypto.core.DSAParams jceKey.getParams.getP, jceKey.getParams.getQ, jceKey.getParams.getG; } { Example code to convert an DHPrivateKey to OSDT DHPrivateKey jceKey = null; Note calculate q = p-12 oracle.security.crypto.core.DHPrivateKey osdtKey = new oracle.security.crypto.core.DHPrivateKey jceKey.getX, new oracle.security.crypto.core.DHParams jceKey.getParams.getP, jceKey.getParams.getG, jceKey.getParams.getP.subtractnew BigInteger1.dividenew BigInteger2; }

2.3 JCE Certificates