Examples of KeySpec


Examples of java.security.spec.KeySpec

        int iterationCount = 19;

        try
        {

            KeySpec keySpec = new PBEKeySpec( passPhrase.toCharArray(), salt, iterationCount );
            SecretKey key = SecretKeyFactory.getInstance( "PBEWithMD5AndDES" ).generateSecret( keySpec );

            ecipher = Cipher.getInstance( "PBEWithMD5AndDES" );
            // changed only this line of code, which went :
            // ecipher = Cipher.getInstance( key.getAlgorithm() ); and raised an exception
View Full Code Here

Examples of java.security.spec.KeySpec

        // Flip bytes (reverse bits) in key
        for (int i = 0; i < key.length; i++) {
            key[i] = flipByte(key[i]);
        }

        KeySpec desKeySpec = new DESKeySpec(key);
        SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey secretKey = secretKeyFactory.generateSecret(desKeySpec);
        Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding");
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
View Full Code Here

Examples of java.security.spec.KeySpec

        paramSpec = new PBEParameterSpec(SALT, ITERATION);
    }

    @Override
    public void initKey() throws Exception {
        KeySpec keySpec = new PBEKeySpec(password.toCharArray());
        skey = SecretKeyFactory.getInstance(algorithm).generateSecret(keySpec);
    }
View Full Code Here

Examples of java.security.spec.KeySpec

        }
    }

    void unlock(char[] masterPassword) throws Exception {
        LOG.fine("switching to new master password");
        KeySpec keySpec = new PBEKeySpec(masterPassword);
        Key key = KEY_FACTORY.generateSecret(keySpec);
        encrypt.init(Cipher.ENCRYPT_MODE, key, PARAM_SPEC);
        decrypt.init(Cipher.DECRYPT_MODE, key, PARAM_SPEC);
        unlocked = true;
    }
View Full Code Here

Examples of java.security.spec.KeySpec

      throw new RuntimeException("Unsupported format");
     
    byte[] publicExponent = readElement(dis);
    byte[] modulus = readElement(dis);
   
    KeySpec spec = new RSAPublicKeySpec(new BigInteger(modulus), new BigInteger(publicExponent));
    KeyFactory keyFactory = KeyFactory.getInstance("RSA", BouncyCastleProvider.PROVIDER_NAME);
    RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(spec);
 
    return pubKey;
  }
View Full Code Here

Examples of java.security.spec.KeySpec

        ASN1Sequence    crmfSeq = (ASN1Sequence) in.readObject();
        ASN1Sequence reqSeq =  (ASN1Sequence) ((ASN1Sequence) crmfSeq.getObjectAt(0)).getObjectAt(0);
        CertRequest certReq = new CertRequest( reqSeq );
        SubjectPublicKeyInfo pKeyInfo = certReq.getCertTemplate().getPublicKey();
        KeyFactory keyFact = KeyFactory.getInstance("RSA", "BC");
        KeySpec keySpec = new X509EncodedKeySpec( pKeyInfo.getEncoded() );
        PublicKey pubKey = keyFact.generatePublic(keySpec); // just check it's ok
        imsg = new SimpleRequestMessage(pubKey, username, password);
        // a simple crmf is not a complete PKI message, as desired by the CrmfRequestMessage class
        //PKIMessage msg = PKIMessage.getInstance(new ASN1InputStream(new ByteArrayInputStream(request)).readObject());
        //CrmfRequestMessage reqmsg = new CrmfRequestMessage(msg, null, true, null);
View Full Code Here

Examples of java.security.spec.KeySpec

    Output.p("Initializing security layer with password");
   
    Security.salt = "asdf".getBytes();

    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    KeySpec spec = new PBEKeySpec(password, salt, 1024, 256);
    SecretKey tmp = factory.generateSecret(spec);
    Security.key = new SecretKeySpec(tmp.getEncoded(), "AES");

    Security.cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
  }
View Full Code Here

Examples of java.security.spec.KeySpec

    }

    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

Examples of java.security.spec.KeySpec

        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

Examples of java.security.spec.KeySpec

   
    private static String generatePBKDF2(String pwd, String salt, String algorithm, int iterations, int keyLength) throws NoSuchAlgorithmException {
        // for example PBKDF2WithHmacSHA1
        SecretKeyFactory factory = SecretKeyFactory.getInstance(algorithm);
        byte[] saltBytes = convertHexToBytes(salt);
        KeySpec keyspec = new PBEKeySpec(pwd.toCharArray(), saltBytes, iterations, keyLength);
        try {
            Key key = factory.generateSecret(keyspec);
            byte[] bytes = key.getEncoded();
            return convertBytesToHex(bytes);
        } catch (InvalidKeySpecException e) {
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.