Package gnu.crypto.pad

Examples of gnu.crypto.pad.IPad


   */
  public static byte[] encryptString(byte[] source, byte[] mykey, byte[] i_iv) {
    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);
View Full Code Here


   */
  public static byte[] decryptString(byte[] source, byte[] mykey, byte[] i_iv) {

    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];
        System.arraycopy(ct, 0, out, 0, out.length);
      } catch (Exception e) {
        out = new byte[ct.length];
        System.arraycopy(ct, 0, out, 0, out.length);
View Full Code Here

TOP

Related Classes of gnu.crypto.pad.IPad

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.