Package java.security.spec

Examples of java.security.spec.KeySpec


  public SecretKey getKeyFromPassword(String passPhrase, byte[] salt) {
    SecretKeyFactory factory;
    SecretKey key = null;
    try {
      factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
      KeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), salt, ITERATION_COUNT, KEY_LENGTH);
      key = factory.generateSecret(spec);
    } catch (NoSuchAlgorithmException e) {
      LOG.failedToGenerateKeyFromPassword( e );
    } catch (InvalidKeySpecException e) {
      LOG.failedToGenerateKeyFromPassword( e );
View Full Code Here


         
          try
          {
              PBEParameterSpec params = new PBEParameterSpec(salt, iterationCount);
             
              KeySpec keySpec = new PBEKeySpec(passphrase.toCharArray());
              SecretKey key = SecretKeyFactory.getInstance(ALGORITHM, "SunJCE").generateSecret(keySpec);
             
              this.characterEncoding = characterEncoding;
              this.encryptCipher = Cipher.getInstance(ALGORITHM, "SunJCE");
              this.encryptCipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key, params);
View Full Code Here

    }

    private PublicKey readPublicKey(String endMarker)
        throws IOException
    {
        KeySpec keySpec = new X509EncodedKeySpec(readBytes(endMarker));
        String[] algorithms = { "DSA", "RSA" };
        for (int i = 0; i < algorithms.length; i++)
        {
            try
            {
View Full Code Here

        else
        {
            keyBytes = Base64.decode(buf.toString());
        }

        KeySpec                 pubSpec, privSpec;
        ByteArrayInputStream    bIn = new ByteArrayInputStream(keyBytes);
        ASN1InputStream         aIn = new ASN1InputStream(bIn);
        ASN1Sequence            seq = (ASN1Sequence)aIn.readObject();

        if (type.equals("RSA"))
View Full Code Here

    }
    if (ecipher == null) {
      try {
        SecretKey key;
        try{
          KeySpec keySpec = new PBEKeySpec(passPhrase, mSalt, iterationCount);
          key = SecretKeyFactory.getInstance(mAlgorithm).generateSecret(keySpec);
        }
        catch (final java.security.spec.InvalidKeySpecException e) {
          try {
                      passPhrase = URLEncoder.encode(new String(passPhrase)"UTF-8").toCharArray();
                    }
                    catch (UnsupportedEncodingException e1) {
                      throw e;
                    }
          KeySpec keySpec = new PBEKeySpec(passPhrase, mSalt, iterationCount);
          key = SecretKeyFactory.getInstance(mAlgorithm).generateSecret(keySpec);
        }
        ecipher = Cipher.getInstance(mAlgorithm);
        dcipher = Cipher.getInstance(mAlgorithm);
        final AlgorithmParameterSpec paramSpec = new PBEParameterSpec(mSalt, iterationCount);
View Full Code Here

    }

    private PublicKey readPublicKey(String endMarker)
        throws IOException
    {
        KeySpec keySpec = new X509EncodedKeySpec(readBytes(endMarker));
        String[] algorithms = { "DSA", "RSA" };
        for (int i = 0; i < algorithms.length; i++)
        {
            try
            {
View Full Code Here

            keyBytes = PEMUtilities.crypt(false, provider, keyBytes, password, dekAlgName, iv);
        }


        KeySpec                 pubSpec, privSpec;
        ByteArrayInputStream    bIn = new ByteArrayInputStream(keyBytes);
        ASN1InputStream         aIn = new ASN1InputStream(bIn);
        ASN1Sequence            seq = (ASN1Sequence)aIn.readObject();

        if (type.equals("RSA"))
View Full Code Here

        for (int specOffset = 0; specOffset < spec.length; specOffset++) {
            keyOffset = (keyOffset + 7) % encryptionKey.length();
            spec[specOffset] = encryptionKey.getBytes()[keyOffset];
        }
       
        KeySpec keySpec = new DESedeKeySpec(encryptionKey.getBytes());
        algParamSpec = new IvParameterSpec(spec);
        key = SecretKeyFactory.getInstance(encryptionScheme).generateSecret(keySpec);       
    }
View Full Code Here

        return  null;
    }

    private static PublicKey readPublicKey(byte[] input, String alg, String endMarker) throws IOException {
        KeySpec keySpec = new X509EncodedKeySpec(input);
        try {
            KeyFactory keyFact = KeyFactory.getInstance(alg);
            PublicKey pubKey = keyFact.generatePublic(keySpec);
            return pubKey;
        } catch (NoSuchAlgorithmException e) {
View Full Code Here

        for (int specOffset = 0; specOffset < spec.length; specOffset++) {
            keyOffset = (keyOffset + 7) % encryptionKey.length();
            spec[specOffset] = encryptionKey.getBytes()[keyOffset];
        }
       
        KeySpec keySpec = new DESedeKeySpec(encryptionKey.getBytes());
        algParamSpec = new IvParameterSpec(spec);
        key = SecretKeyFactory.getInstance(encryptionScheme).generateSecret(keySpec);       
    }
View Full Code Here

TOP

Related Classes of java.security.spec.KeySpec

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.