Package javax.crypto

Examples of javax.crypto.Cipher.unwrap()


            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


            SecretKey k = kg.generateKey();

            c1.init(Cipher.WRAP_MODE, k);
            c2.init(Cipher.UNWRAP_MODE, k);

            Key wKey = c2.unwrap(c1.wrap(new SecretKeySpec(data, algorithm)), algorithm, Cipher.SECRET_KEY);

            if (!areEqual(data, wKey.getEncoded()))
            {
                fail("failed wrap OID test");
            }
View Full Code Here

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

        try
        {
            Key  pText = wrapper.unwrap(out, algorithm, Cipher.SECRET_KEY);
            if (!areEqual(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

      }

      tripleDESWrapper.init(Cipher.UNWRAP_MODE,
                            new SecretKeySpec(KEKbytes, "DESEDE"));

      Key plaintextKey = tripleDESWrapper.unwrap(realCipherTextBytes, "DESEDE",
                                                 Cipher.SECRET_KEY);
      byte realPlainTextBytes[] = plaintextKey.getEncoded();

      if (!MessageDigest.isEqual(realPlainTextBytes, keyDataBytes)) {
         return false;
View Full Code Here

         return false;
      }

      aesWrapper.init(Cipher.UNWRAP_MODE, new SecretKeySpec(KEKbytes, "AES"));

      Key plaintextKey = aesWrapper.unwrap(realCipherTextBytes, "AES",
                                           Cipher.SECRET_KEY);
      byte realPlainTextBytes[] = plaintextKey.getEncoded();

      if (!MessageDigest.isEqual(realPlainTextBytes, keyDataBytes)) {
         return false;
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

          }
        kwa.init(Cipher.UNWRAP_MODE, kek128);
        msg = "MUST NOT be able to call unwrap() with a different 'wrappedKeyType'";
        try
          {
            kwa.unwrap(cipherText, "AES", Cipher.PRIVATE_KEY);
            harness.fail(msg);
          }
        catch (NoSuchAlgorithmException x)
          {
            harness.check(true, msg);
View Full Code Here

        harness.check(Arrays.equals(cipherText, KM128_WRAPPED128),
                      "128-bit key material wrapped w/ 128-bit KEK MUST match "
                      + "expected value");

        kwa.init(Cipher.UNWRAP_MODE, kek);
        Key k = kwa.unwrap(cipherText, "AES", Cipher.SECRET_KEY);
        harness.check(km.equals(k),
                      "Unwrapped and original key-material MUST match");
      }
    catch (Exception x)
      {
View Full Code Here

        harness.check(Arrays.equals(cipherText, KM192_WRAPPED192),
                      "192-bit key material wrapped w/ 192-bit KEK MUST match "
                      + "expected value");

        kwa.init(Cipher.UNWRAP_MODE, kek);
        Key k = kwa.unwrap(cipherText, "AES", Cipher.SECRET_KEY);
        harness.check(km.equals(k),
                      "Unwrapped and original key-material MUST match");
      }
    catch (Exception x)
      {
View Full Code Here

        harness.check(Arrays.equals(cipherText, KM256_WRAPPED256),
                      "256-bit key material wrapped w/ 256-bit KEK MUST match "
                      + "expected value");

        kwa.init(Cipher.UNWRAP_MODE, kek);
        Key k = kwa.unwrap(cipherText, "AES", Cipher.SECRET_KEY);
        harness.check(km.equals(k),
                      "Unwrapped and original key-material MUST match");
      }
    catch (Exception x)
      {
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.