Package javax.crypto

Examples of javax.crypto.Cipher.unwrap()


            Key wrapKey = keyGen.generateKey();
            cipher.init(Cipher.WRAP_MODE, wrapKey);
            byte[] wrappedKey = cipher.wrap(priKey);

            cipher.init(Cipher.UNWRAP_MODE, wrapKey);
            Key key = cipher.unwrap(wrappedKey, "RSA", Cipher.PRIVATE_KEY);

            if (!MessageDigest.isEqual(priKey.getEncoded(), key.getEncoded()))
            {
                return new SimpleTestResult(false, "Unwrapped key does not match");
            }
View Full Code Here


            wrapper.init(Cipher.UNWRAP_MODE, new SecretKeySpec(kek, "DESEDE"));

            try
            {
                Key  pText = wrapper.unwrap(out, "DESede", Cipher.SECRET_KEY);
                if (!equalArray(pText.getEncoded(), in))
                {
                    fail("failed unwrap test " + id  + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText.getEncoded())));
                }
            }
View Full Code Here

            Cipher cipher = Cipher.getInstance(algorithm, "BC");

            cipher.init(Cipher.UNWRAP_MODE, k, defParams);

            // we pass "" as the key algorithm type as it is unknown at this point
            out = (PrivateKey)cipher.unwrap(data, "", Cipher.PRIVATE_KEY);
        }
        catch (Exception e)
        {
            throw new IOException("exception unwrapping private key - " + e.toString());
        }
View Full Code Here

    Key ret;

    try {   
      c.init(Cipher.UNWRAP_MODE, _key);
      ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);
     
    } catch (InvalidKeyException ike) {
      throw new XMLEncryptionException("empty", ike);
    } catch (NoSuchAlgorithmException nsae) {
      throw new XMLEncryptionException("empty", nsae);
View Full Code Here

    Key ret;

    try {   
      c.init(Cipher.UNWRAP_MODE, _key);
      ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);
     
    } catch (InvalidKeyException ike) {
      throw new XMLEncryptionException("empty", ike);
    } catch (NoSuchAlgorithmException nsae) {
      throw new XMLEncryptionException("empty", nsae);
View Full Code Here

    Key ret;

    try {   
      c.init(Cipher.UNWRAP_MODE, _key);
      ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);
     
    } catch (InvalidKeyException ike) {
      throw new XMLEncryptionException("empty", ike);
    } catch (NoSuchAlgorithmException nsae) {
      throw new XMLEncryptionException("empty", nsae);
View Full Code Here

    Key ret;

    try {   
      c.init(Cipher.UNWRAP_MODE, _key);
      ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);
     
    } catch (InvalidKeyException ike) {
      throw new XMLEncryptionException("empty", ike);
    } catch (NoSuchAlgorithmException nsae) {
      throw new XMLEncryptionException("empty", nsae);
View Full Code Here

      Cipher cipher = Cipher.getInstance("RSA");
     
      // Unwrap 'key' with the RSA key into a Key object
      cipher.init(Cipher.UNWRAP_MODE, rsaPubKey);
      byte[] keyBytes = base64.decode(key);
      Key aesKey = cipher.unwrap(keyBytes, "AES", Cipher.SECRET_KEY);
     
      // Decrypt 'iv' with the RSA key into a IvParameterSpec object
      byte[] ivBytes = base64.decode(iv);
      cipher.init(Cipher.DECRYPT_MODE, rsaPubKey);
      byte[] ivDecrypted = cipher.doFinal(ivBytes);
View Full Code Here

            Cipher cipher = Cipher.getInstance(algorithm, "BC");

            cipher.init(Cipher.UNWRAP_MODE, k, defParams);

            // we pass "" as the key algorithm type as it is unknown at this point
            out = (PrivateKey)cipher.unwrap(data, "", Cipher.PRIVATE_KEY);
        }
        catch (Exception e)
        {
            throw new IOException("exception unwrapping private key - " + e.toString());
        }
View Full Code Here

                Key ret;

                try {
                        c.init(Cipher.UNWRAP_MODE, _key);
                        ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);

                } catch (InvalidKeyException ike) {
                        throw new XMLEncryptionException("empty", ike);
                } catch (NoSuchAlgorithmException nsae) {
                        throw new XMLEncryptionException("empty", nsae);
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.