Package java.security.spec

Examples of java.security.spec.PKCS8EncodedKeySpec


    return cert;
  }

  public static PrivateKey getPrivateKeyFromBytes(byte[] derKey) throws GeneralSecurityException {
    KeyFactory fac = KeyFactory.getInstance("RSA");
    EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(derKey);
    return fac.generatePrivate(privKeySpec);
  }
View Full Code Here


  }

  private PrivateKey getPrivateKey(InputStream privateKeyStream)
      throws SignatureException {
    try {
      PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(
          readBase64Bytes(privateKeyStream));
      KeyFactory keyFac = KeyFactory.getInstance("RSA");
      return keyFac.generatePrivate(keySpec);
    } catch (NoSuchAlgorithmException e) {
      throw new SignatureException(e);
View Full Code Here

        if (parse == null)
            throw new IllegalArgumentException("invalid key file contents");

        if (parse[0].length() == 0) { // BEGIN PRIVATE KEY
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(Base64.decode(parse[1])));
        }

        if (parse[0].contains("RSA")) { // BEGIN RSA PRIVATE KEY
            Security.addProvider(new BouncyCastleProvider());
View Full Code Here

            KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());

            store.load(null, password.toCharArray());
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            store.load(null, password.toCharArray());
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(
                    StringUtils.convertHexToBytes("30820277020100300d06092a864886f70d010101"
                            + "0500048202613082025d02010002818100dc0a13" + "c602b7141110eade2f051b54777b060d0f74e6a1"
                            + "10f9cce81159f271ebc88d8e8aa1f743b505fc2e" + "7dfe38d33b8d3f64d1b363d1af4d877833897954"
                            + "cbaec2fa384c22a415498cf306bb07ac09b76b00" + "1cd68bf77ea0a628f5101959cf2993a9c23dbee7"
                            + "9b19305977f8715ae78d023471194cc900b231ee" + "cb0aaea98d02030100010281810099aa4ff4d0a0"
View Full Code Here

        Class    spec)
    throws InvalidKeySpecException
    {
       if (spec.isAssignableFrom(PKCS8EncodedKeySpec.class) && key.getFormat().equals("PKCS#8"))
       {
               return new PKCS8EncodedKeySpec(key.getEncoded());
       }
       else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
       {
               return new X509EncodedKeySpec(key.getEncoded());
       }
View Full Code Here

    String str = new String(privKeyBytes);
    if (str.startsWith(BEGIN) && str.endsWith(END)) {
      str = str.substring(BEGIN.length(), str.lastIndexOf(END));
    }
    KeyFactory fac = KeyFactory.getInstance("RSA");
    EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(str));
    return fac.generatePrivate(privKeySpec);
  }
View Full Code Here

        FileInputStream fis = new FileInputStream(file);
        byte[] data = new byte[(int)file.length()];
        fis.read(data);
        fis.close();

        PKCS8EncodedKeySpec kspec = new PKCS8EncodedKeySpec(data);
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = kf.generatePrivate(kspec);

        return privateKey;
    }
View Full Code Here

            byte[] encPubKey = pubKey.getEncoded();
            byte[] encPrivKey = privKey.getEncoded();

            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encPubKey);
            PKCS8EncodedKeySpec privKeySpec = new PKCS8EncodedKeySpec(
                encPrivKey);

            PublicKey decPubKey = kf.generatePublic(pubKeySpec);
            PrivateKey decPrivKey = kf.generatePrivate(privKeySpec);
View Full Code Here

    {
        if (key instanceof BCRainbowPrivateKey)
        {
            if (PKCS8EncodedKeySpec.class.isAssignableFrom(keySpec))
            {
                return new PKCS8EncodedKeySpec(key.getEncoded());
            }
            else if (RainbowPrivateKeySpec.class.isAssignableFrom(keySpec))
            {
                BCRainbowPrivateKey privKey = (BCRainbowPrivateKey)key;
                return new RainbowPrivateKeySpec(privKey.getInvA1(), privKey
View Full Code Here

  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfPR28556");
    KeyFactory kf;
    PKCS8EncodedKeySpec spec;
    try
      {
        kf = KeyFactory.getInstance("RSA");
        spec = new PKCS8EncodedKeySpec(Util.toBytesFromUnicode(RSA_KEY_DER));
        kf.generatePrivate(spec);
        harness.check(true,
                      "MUST be able to parse generated OpenSSL RSA private key");
      }
    catch (Exception x)
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.