Examples of PKCS8EncodedKeySpec


Examples of java.security.spec.PKCS8EncodedKeySpec

            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

Examples of java.security.spec.PKCS8EncodedKeySpec

      } else if (type == Type.PUBLIC && X509.equals(format)) {
    KeyFactory f = KeyFactory.getInstance(algorithm);
    return f.generatePublic(new X509EncodedKeySpec(encoded));
      } else if (type == Type.PRIVATE && PKCS8.equals(format)) {
    KeyFactory f = KeyFactory.getInstance(algorithm);
    return f.generatePrivate(new PKCS8EncodedKeySpec(encoded));
      } else {
    throw new NotSerializableException
      ("unrecognized type/format combination: " +
      type + "/" + format);
      }
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

  keyFact = KeyFactory.getInstance(algorithm);
  sign = Signature.getInstance(signAlgorithm);
    }
   
    public PrivateKey getPrivateKeyFromBytes(byte[] keyBuffer) throws InvalidKeySpecException {
  return keyFact.generatePrivate(new PKCS8EncodedKeySpec(keyBuffer));
    }
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

                Security.addProvider(bp);
            }

           

            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encKey);
            KeyFactory factory = KeyFactory.getInstance(SOSKeyGenerator.keyAlgorithmName,
                    SOSKeyGenerator.provider);

            priv = factory.generatePrivate(keySpec);
      
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

      dis.close();
    }
   
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
   
    final PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(privKeyBytes);
   
    final PrivateKey privateKey = keyFactory.generatePrivate(privSpec);
   
    this.digester = MessageDigest.getInstance("sha-256");
   
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

        int dataLength = dataEnd - dataStart;
        byte[] keyContent = new byte[dataLength];

        System.arraycopy(keyBytes, dataStart, keyContent, 0, dataLength);

        PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
                new Base64().decode(keyContent));
        try {
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            return keyFactory.generatePrivate(pkcs8EncodedKeySpec);
        } catch (NoSuchAlgorithmException e) {
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

        if (basedir != null && !"".equals(basedir)) {
            filename = basedir + "/" + filename;
        }

        byte[] pkcs8Bytes = JavaUtils.getBytesFromFile(filename);
        PKCS8EncodedKeySpec pkcs8Spec = new PKCS8EncodedKeySpec(pkcs8Bytes);

        // Create a key factory
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        rsaKey = keyFactory.generatePrivate(pkcs8Spec);
    }
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

      try {
        PemReader reader = new PemReader(new StringReader(s));
        PemObject pemObject = reader.readPemObject();
        reader.close();

        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemObject.getContent());
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = kf.generatePrivate(keySpec);
        if (privateKey instanceof RSAPrivateCrtKey) {
          RSAPrivateCrtKey rsaPrivateCrtKey = (RSAPrivateCrtKey) privateKey;
          RSAPublicKeySpec publicKeySpec = new java.security.spec.RSAPublicKeySpec(
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

  }

  private PrivateKey tryParsePemFormat(String data) {
    try {
      byte[] encoded = Base64.decode(data);
      PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
      KeyFactory kf = KeyFactory.getInstance("RSA");
      PrivateKey privKey = kf.generatePrivate(keySpec);

      return privKey;
    } catch (Exception e) {
View Full Code Here

Examples of java.security.spec.PKCS8EncodedKeySpec

    }
    return pubKey;
  }

  public static PrivateKey deserializePrivateKey(byte[] keyData) {
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyData);

    KeyFactory keyFactory = getKeyFactory();

    PrivateKey privateKey;
    try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.