Package gnu.javax.crypto.kwa

Examples of gnu.javax.crypto.kwa.IKeyWrappingAlgorithm


  private void testMethods(TestHarness harness)
  {
    byte[] kek = new byte[24];
    try
      {
        IKeyWrappingAlgorithm kwa = KeyWrappingAlgorithmFactory.getInstance("kw-tripledes");
        Map attributes = new HashMap();
        attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek);
        kwa.init(attributes);

        String msg;
        byte[] km = new byte[24];
        msg = "Input length for wrapping MUST be 16 or 24 bytes";
        try
          {
            kwa.wrap(km, 0, 15);
            harness.fail(msg);
          }
        catch (IllegalArgumentException e)
          {
            harness.check(true, msg);
          }

        msg = "Input length for unwrapping MUST be 40 bytes";
        try
          {
            kwa.unwrap(km, 0, 24);
            harness.fail(msg);
          }
        catch (IllegalArgumentException e)
          {
            harness.check(true, msg);
View Full Code Here


        (byte) 0x86, (byte) 0x0d, (byte) 0x3e, (byte) 0x98 };
    try
      {
        TripleDES.adjustParity(km, 0);

        IKeyWrappingAlgorithm kwa = KeyWrappingAlgorithmFactory.getInstance("kw-tripledes");
        Map attributes = new HashMap();
        attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek);
        kwa.init(attributes);

        byte[] wrapped = kwa.wrap(km, 0, km.length);
        harness.check(wrapped.length == 40,
                      "Wrapped key material MUST produce 40 bytes");

        byte[] unwrapped = kwa.unwrap(wrapped, 0, wrapped.length);
        harness.check(unwrapped.length == 24,
                      "Unwrapped key material MUST produce 24 bytes");
        harness.check(Arrays.equals(km, unwrapped),
                      "Unwrapped key material MUST match original value");
      }
View Full Code Here

  private void testMethods(TestHarness harness)
  {
    byte[] kek = new byte[16];
    try
      {
        IKeyWrappingAlgorithm kwa = KeyWrappingAlgorithmFactory.getInstance("kw-aes");
        Map attributes = new HashMap();
        attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek);
        kwa.init(attributes);

        String msg;
        byte[] km1 = new byte[24];
        msg = "Input length MUST be a multiple of 8 bytes";
        try
          {
            kwa.wrap(km1, 0, 17, km1, 0);
            harness.fail(msg);
          }
        catch (IllegalArgumentException e)
          {
            harness.check(true, msg);
          }

        msg = "Output length MUST be at least 8 bytes larger than input length";
        try
          {
            kwa.wrap(km1, 0, 16, km1, 1);
            harness.fail(msg);
          }
        catch (ShortBufferException e)
          {
            harness.check(true, msg);
View Full Code Here

      kek[i] = (byte) i;

    byte[] km = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
    try
      {
        IKeyWrappingAlgorithm kwa = KeyWrappingAlgorithmFactory.getInstance("kw-aes");
        Map attributes = new HashMap();
        attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek);
        kwa.init(attributes);

        byte[] wrapped = new byte[km.length + 8];
        int outputLength = kwa.wrap(km, 0, km.length, wrapped, 0);
        harness.check(outputLength == 16,
                      "Wrapped 64-bit key material MUST produce 16 bytes");

        byte[] unwrapped = new byte[8];
        outputLength = kwa.unwrap(wrapped, 0, wrapped.length, unwrapped, 0);
        harness.check(outputLength == 8,
                      "Unwrapped 128-bit key material MUST produce 8 bytes");
        harness.check(Arrays.equals(km, unwrapped),
                      "Unwrapped key material MUST match original value");
      }
View Full Code Here

      kek[i] = (byte) i;

    int keyMaterialLength = keyMaterial.length * 8;
    try
      {
        IKeyWrappingAlgorithm kwa = KeyWrappingAlgorithmFactory.getInstance("kw-aes");
        Map attributes = new HashMap();
        attributes.put(IKeyWrappingAlgorithm.KEY_ENCRYPTION_KEY_MATERIAL, kek);
        kwa.init(attributes);

        byte[] km = (byte[]) keyMaterial.clone();
        byte[] wrapped = new byte[km.length + 8];
        kwa.wrap(km, 0, km.length, wrapped, 0);
        harness.check(Arrays.equals(wrappedKeyMaterial, wrapped),
                      keyMaterialLength + "-bit key material wrapped w/ "
                      + keyLength + "-bit KEK MUST match expected value");

        byte[] unwrapped = new byte[wrappedKeyMaterial.length - 8];
        kwa.unwrap(wrappedKeyMaterial, 0, wrappedKeyMaterial.length, unwrapped, 0);
        harness.check(Arrays.equals(keyMaterial, unwrapped),
                      keyMaterialLength + "-bit key material unwrapped w/ "
                      + keyLength + "-bit KEK MUST match expected value");
      }
    catch (Exception x)
View Full Code Here

TOP

Related Classes of gnu.javax.crypto.kwa.IKeyWrappingAlgorithm

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.