Package java.security.spec

Examples of java.security.spec.PKCS8EncodedKeySpec


     */
    protected boolean strongCryptoInstalled() throws IOException, KeyStoreException, CertificateException, NoSuchProviderException, NoSuchAlgorithmException,
            InvalidKeySpecException {
        CryptoProviderTools.installBCProvider();
        Certificate cert = CertTools.getCertfromByteArray(certbytes);
        PKCS8EncodedKeySpec pkKeySpec = new PKCS8EncodedKeySpec(keys1024bit);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey pk = keyFactory.generatePrivate(pkKeySpec);
        KeyStore ks = KeyTools.createP12("Foo", pk, cert, (X509Certificate) null);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // If password below is more than 7 chars, strong crypto is needed
View Full Code Here


          String certFile = args[3];
         
          // Import key and certificate
          CryptoProviderTools.installBCProvider();
      byte[] pkbytes = FileTools.readFiletoBuffer(pkFile);
          PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(pkbytes);
          KeyFactory keyfact = KeyFactory.getInstance("RSA", "BC"); // Doesn't matter if we say RSA here, it will fix an EC key as well
          PrivateKey privKey = keyfact.generatePrivate(spec);           

          byte[] certbytes = FileTools.readFiletoBuffer(certFile);
          Certificate cert = null;
View Full Code Here

    CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");
    return (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certroottest));
  }
 
  public static PrivateKey getUserKey() throws Exception{
        PKCS8EncodedKeySpec pkKeySpec = new PKCS8EncodedKeySpec(userkey);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        return keyFactory.generatePrivate(pkKeySpec);
  }
View Full Code Here

          byte[] der = request.getDEREncoded();
          if (authSignKeyFile != null) {
            getPrintStream().println("Reading private key from pkcs8 file "+authSignKeyFile+" to create an authenticated request");
            byte[] keybytes = FileTools.readFiletoBuffer(authSignKeyFile);
                KeyFactory keyfact = KeyFactory.getInstance(keytype, "BC");
                PrivateKey privKey = keyfact.generatePrivate(new PKCS8EncodedKeySpec(keybytes));
                KeyPair authKeyPair = new KeyPair(null, privKey); // We don't need the public key
                // Default caRef if we do not pass in a certificate to get caRef from
            CAReferenceField authCaRef = new CAReferenceField(country,mnemonic,sequence);
            CVCertificate authCert = null;
            if (authSignCertFile != null) {
View Full Code Here

    }

    public void test03CreateP12() throws Exception {
        log.trace(">test03CreateP12()");
        Certificate cert = CertTools.getCertfromByteArray(certbytes);
        PKCS8EncodedKeySpec pkKeySpec = new PKCS8EncodedKeySpec(keys1024bit);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PrivateKey pk = keyFactory.generatePrivate(pkKeySpec);
        KeyStore ks = KeyTools.createP12("Foo", pk, cert, (X509Certificate) null);
        assertNotNull("ks must not be null", ks);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
View Full Code Here

    //End

    protected void retrievePriKey(File keyFile) throws Exception {
        byte[] priKeyByte = readByte(keyFile);
        KeyFactory keyFac = KeyFactory.getInstance(this.algorithm);
        PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(priKeyByte);
        priKey = keyFac.generatePrivate(encodedKeySpec);
    }
View Full Code Here

        return cf.generateCertificate(bis);
    }

    public static Key buildPrivateKey(String base64EncodedKeyContent) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException {
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PKCS8EncodedKeySpec  keysp = new PKCS8EncodedKeySpec (Base64.decodeBase64(base64EncodedKeyContent));
        return kf.generatePrivate (keysp);
    }
View Full Code Here

    }

    public static void importPKCS8CertChain(KeyStore ks, String alias, byte[] keyBytes, String keyPass, byte[] certChain) throws InvalidKeySpecException, NoSuchAlgorithmException, CertificateException, KeyStoreException {
        // load the private key
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec(keyBytes);
        PrivateKey pk = kf.generatePrivate(keysp);

        // load the cert chain
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        ByteArrayInputStream bais = new ByteArrayInputStream(certChain);
View Full Code Here

                Messages.getString("security.0C", type, format)); //$NON-NLS-1$
        case PRIVATE:
            if ("PKCS#8".equals(format)) { //$NON-NLS-1$
                try {
                    KeyFactory kf = KeyFactory.getInstance(algorithm);
                    return kf.generatePrivate(new PKCS8EncodedKeySpec(encoded));
                } catch (NoSuchAlgorithmException e) {
                    throw new NotSerializableException(
                            Messages.getString("security.0D", e)); //$NON-NLS-1$
                }
                catch (InvalidKeySpecException e) {
View Full Code Here

                    return (T) (new DSAPrivateKeySpec(x, p, q, g));
                }

                if (keySpec.equals(PKCS8EncodedKeySpec.class)) {
                    return (T) (new PKCS8EncodedKeySpec(key.getEncoded()));
                }

                throw new InvalidKeySpecException(Messages
                        .getString("security.19C")); //$NON-NLS-1$
            }
View Full Code Here

TOP

Related Classes of java.security.spec.PKCS8EncodedKeySpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.