Package gnu.javax.crypto.cipher

Examples of gnu.javax.crypto.cipher.TripleDES


  private HashMap attributes = new HashMap();

  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfTripleDES");
    cipher = new TripleDES();
    HashMap attrib = new HashMap();
    attrib.put(IBlockCipher.CIPHER_BLOCK_SIZE, new Integer(8));
    attrib.put(IBlockCipher.KEY_MATERIAL, new byte[24]);

    boolean oldCheckForWeakKeys = Properties.checkForWeakKeys();
View Full Code Here


    byte[] pt, ct;
    byte[] ct1 = new byte[8];
    byte[] ct2 = new byte[8];

    HashMap map = new HashMap();
    IBlockCipher desEDE = new TripleDES();

    HashMap map1 = new HashMap();
    HashMap map2 = new HashMap();
    HashMap map3 = new HashMap();
    Cascade new3DES = new Cascade();
    Object des1 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.FORWARD));
    Object des2 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.REVERSED));
    Object des3 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.FORWARD));

    map.put(des1, map1);
    map.put(des2, map2);
    map.put(des3, map3);

    for (int i = 0; i < E_TV.length; i++)
      {
        map1.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][0]));
        map2.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][1]));
        map3.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][2]));
        map.put(IBlockCipher.KEY_MATERIAL,
                Util.toBytesFromString(E_TV[i][0] + E_TV[i][1] + E_TV[i][2]));
        map.put(Cascade.DIRECTION, Direction.FORWARD);
        pt = Util.toBytesFromString(E_TV[i][3]);
        ct = Util.toBytesFromString(E_TV[i][4]);

        try
          {
            desEDE.reset();
            new3DES.reset();

            desEDE.init(map);
            new3DES.init(map);

            desEDE.encryptBlock(pt, 0, ct1, 0);
            new3DES.update(pt, 0, ct2, 0);
            harness.check(Arrays.equals(ct1, ct2));

            for (int j = 0; j < 9999; j++)
              {
                desEDE.encryptBlock(ct1, 0, ct1, 0);
                new3DES.update(ct2, 0, ct2, 0);
              }
            harness.check(Arrays.equals(ct, ct1));
            harness.check(Arrays.equals(ct, ct2));
          }
        catch (InvalidKeyException x)
          {
            harness.fail("init (encryption)");
            harness.debug(x);
          }
      }

    for (int i = 0; i < D_TV.length; i++)
      {
        map1.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][0]));
        map2.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][1]));
        map3.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][2]));
        map.put(IBlockCipher.KEY_MATERIAL,
                Util.toBytesFromString(D_TV[i][0] + D_TV[i][1] + D_TV[i][2]));
        map.put(Cascade.DIRECTION, Direction.REVERSED);
        pt = Util.toBytesFromString(D_TV[i][3]);
        ct = Util.toBytesFromString(D_TV[i][4]);

        try
          {
            desEDE.reset();
            new3DES.reset();

            desEDE.init(map);
            new3DES.init(map);

            desEDE.decryptBlock(pt, 0, ct1, 0);
            new3DES.update(pt, 0, ct2, 0);
            harness.check(Arrays.equals(ct1, ct2));

            for (int j = 0; j < 9999; j++)
              {
                desEDE.decryptBlock(ct1, 0, ct1, 0);
                new3DES.update(ct2, 0, ct2, 0);
              }
            harness.check(Arrays.equals(ct, ct1));
            harness.check(Arrays.equals(ct, ct2));
          }
View Full Code Here

TOP

Related Classes of gnu.javax.crypto.cipher.TripleDES

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.