Package java.security.spec

Examples of java.security.spec.X509EncodedKeySpec


     */
    private PublicKey generatePubKey(byte[] encodedKey) {
        PublicKey pubKey=null;
        try {
            KeyFactory KeyFac=KeyFactory.getInstance(getAlgorithm(asymAlgorithm));
            X509EncodedKeySpec x509KeySpec=new X509EncodedKeySpec(encodedKey);
            pubKey=KeyFac.generatePublic(x509KeySpec);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
View Full Code Here


   */
  private static final Key decryptBlowfishKey(byte[] encryptedKey)
  {
    SecretKeySpec blowfishKey = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, publicKey);
View Full Code Here

   */
  private static final byte[] encryptBlowfishKey(Key blowfishKey)
  {
    byte[] returnByteArray = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);
View Full Code Here

    if (privateKey == null) {
      throw new IllegalStateException(
          "KeyGenerator did not successfully generate public key"); //$NON-NLS-1$
    }
    try {
      X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(
          peerPublicKeyBytes);
      KeyFactory keyFact = KeyFactory.getInstance(ALGORITHM);
      PublicKey publicKey = keyFact.generatePublic(x509KeySpec);

      KeyAgreement ka = KeyAgreement.getInstance(ALGORITHM);
View Full Code Here

           {
                   return new PKCS8EncodedKeySpec(key.getEncoded());
           }
           else if (spec.isAssignableFrom(X509EncodedKeySpec.class) && key.getFormat().equals("X.509"))
           {
                   return new X509EncodedKeySpec(key.getEncoded());
           }
           else if (spec.isAssignableFrom(RSAPublicKeySpec.class) && key instanceof RSAPublicKey)
           {
                RSAPublicKey    k = (RSAPublicKey)key;
View Full Code Here

    {
        SubjectPublicKeyInfo    subjectPKInfo = reqInfo.getSubjectPublicKeyInfo();

        try
        {
            X509EncodedKeySpec      xspec = new X509EncodedKeySpec(new DERBitString(subjectPKInfo).getBytes());
            AlgorithmIdentifier     keyAlg = subjectPKInfo.getAlgorithmId ();

            return KeyFactory.getInstance(keyAlg.getObjectId().getId (), provider).generatePublic(xspec);
        }
        catch (InvalidKeySpecException e)
View Full Code Here

  try {
      if (type == Type.SECRET && RAW.equals(format)) {
    return new SecretKeySpec(encoded, algorithm);
      } 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
View Full Code Here

    public PrivateKey getPrivateKeyFromBytes(byte[] keyBuffer) throws InvalidKeySpecException {
  return keyFact.generatePrivate(new PKCS8EncodedKeySpec(keyBuffer));
    }
   
    public PublicKey getPublicKeyFromBytes(byte[] keyBuffer) throws InvalidKeySpecException {
  return keyFact.generatePublic(new X509EncodedKeySpec(keyBuffer))
    }
View Full Code Here

            }

            byte[] encKey = readFromFile(keyFile);
           
            /* erzeugen key spezifikation */
            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
           
            KeyFactory keyFactory = KeyFactory.getInstance(
                    SOSKeyGenerator.keyAlgorithmName, SOSKeyGenerator.provider);
           
            pubKey = keyFactory.generatePublic(pubKeySpec);
View Full Code Here

    private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
        String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
        byte[] keyBytes = Base64.decode(fileData);
        KeyFactory kf = KeyFactory.getInstance(algorithm);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        return kf.generatePublic(keySpec);
    }
View Full Code Here

TOP

Related Classes of java.security.spec.X509EncodedKeySpec

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.