Package gnu.crypto.mode

Examples of gnu.crypto.mode.IMode


      BASE64Decoder base64 = new BASE64Decoder();
      byte[] byHash = base64.decodeBuffer(strHash);
      byte[] byKey = getVersionPassword(hci.cVersion, hci.cSubVersion);
      byte[] byIV = getIV(hci.cVersion, hci.cSubVersion);
     
      IMode mode = ModeFactory.getInstance("CBC", "AES", 32);
      Map attributes = new HashMap();
      attributes.put(IMode.KEY_MATERIAL, byKey);
      attributes.put(IMode.CIPHER_BLOCK_SIZE, new Integer(32));
     
      attributes.put(IMode.STATE, new Integer(IMode.DECRYPTION));
      attributes.put(IMode.IV, byIV);
     
      mode.init(attributes);
      int bs = mode.currentBlockSize();
     
      byte[] byH;     
      if ((byHash.length % 256) == 0)
        byH = new byte[byHash.length];
      else
        byH = new byte[byHash.length + (256 - (byHash.length % 256))];
      for (int i = 0; i < byHash.length; ++i)
        byH[i] = byHash[i];
     
      for (int i = 0; i + bs < byH.length; i += bs)
        mode.update(byH, i, byOut, i);
     
      return byHash.length;
    } catch (Throwable e) {};
    return 0;
  }
View Full Code Here


    byte[] ct = null;

    try {
      IPad padding = PadFactory.getInstance("PKCS7");
      padding.init(16);
      IMode mode = ModeFactory.getInstance("CBC", "AES", 16);
      Map attributes = new HashMap();
      byte[] pt1 = source;
      byte[] pad = padding.pad(pt1, 0, pt1.length);
      byte[] pt = null;
      // 判断是否要补空
      if (pad.length == 16) {
        pt = new byte[pt1.length];
        System.arraycopy(pt1, 0, pt, 0, pt1.length);
      } else {
        pt = new byte[pt1.length + pad.length];
        System.arraycopy(pt1, 0, pt, 0, pt1.length);
        System.arraycopy(pad, 0, pt, pt1.length, pad.length);
      }

      ct = new byte[pt.length];

      byte[] iv = i_iv;
      byte[] key = mykey;
      attributes.put(IMode.KEY_MATERIAL, key);
      attributes.put(IMode.CIPHER_BLOCK_SIZE, new Integer(16));
      attributes.put(IMode.IV, iv);
      attributes.put(IMode.STATE, new Integer(IMode.ENCRYPTION));
      mode.init(attributes);

      for (int i = 0; i + 16 <= pt.length; i += 16) {
        mode.update(pt, i, ct, i);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

    byte[] out = null;
    try {
      IPad padding = PadFactory.getInstance("PKCS7");
      padding.init(16);
      IMode mode = ModeFactory.getInstance("CBC", "AES", 16);
      Map attributes = new HashMap();

      byte[] iv = i_iv;
      byte[] ct = new byte[source.length];
      byte[] key = mykey;

      attributes.put(IMode.KEY_MATERIAL, key);
      attributes.put(IMode.CIPHER_BLOCK_SIZE, new Integer(16));
      attributes.put(IMode.IV, iv);
      attributes.put(IMode.STATE, new Integer(IMode.DECRYPTION));
      mode.init(attributes);

      for (int i = 0; i + 16 <= source.length; i += 16) {
        mode.update(source, i, ct, i);
      }

      try {
        int unpad = padding.unpad(ct, 0, ct.length);
        out = new byte[ct.length - unpad];
View Full Code Here

TOP

Related Classes of gnu.crypto.mode.IMode

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.