aes192 加密解密算法java的

求一个aes192 加密解密算法java的
求一个aes192 加密解密算法java的。网上看到的都是128位的,求个192的
------解决思路----------------------
import java.security.*;
   import javax.crypto.*;
   import javax.crypto.spec.*;
   import java.io.*;

   /**
   * This program generates a AES key, retrieves its raw bytes, and
   * then reinstantiates a AES key from the key bytes.
   * The reinstantiated key is used to initialize a AES cipher for
   * encryption and decryption.
   */

   public class AES {

     /**
     * Turns array of bytes into string
     *
     * @param buf Array of bytes to convert to hex string
     * @return Generated hex string
     */
     public static String asHex (byte buf[]) {
      StringBuffer strbuf = new StringBuffer(buf.length * 2);
      int i;

      for (i = 0; i < buf.length; i++) {
       if (((int) buf[i] & 0xff) < 0x10)
    strbuf.append("0");

       strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
      }

      return strbuf.toString();
     }

     public static void main(String[] args) throws Exception {

       String message="This is just an example";

       // Get the KeyGenerator

       KeyGenerator kgen = KeyGenerator.getInstance("AES");
       kgen.init(128); // 192 and 256 bits may not be available

// Generate the secret key specs.
       SecretKey skey = kgen.generateKey();
       byte[] raw = skey.getEncoded();

       SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");

// Instantiate the cipher

       Cipher cipher = Cipher.getInstance("AES");

       cipher.init(Cipher.ENCRYPT_MODE, skeySpec);

       byte[] encrypted =
         cipher.doFinal((args.length == 0 ?
          "This is just an example" : args[0]).getBytes());
       System.out.println("encrypted string: " + asHex(encrypted));

       cipher.init(Cipher.DECRYPT_MODE, skeySpec);
       byte[] original =
         cipher.doFinal(encrypted);
       String originalString = new String(original);
       System.out.println("Original string: " +
         originalString + " " + asHex(original));
     }
   }

------解决思路----------------------
/**
 * leijid
 *
 * Test.java
 *
 * 2014年9月19日
 */
package com.self.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

/**
 * @author leijid
 * 
 */
public class Test {

private static final String AES = "AES";

private static final String ENCODING = "UTF-8";

private static final String AES_ECB_PADDING = "AES/ECB/NoPadding";

private static final int AES_KEY_LENGTH = 192;

private static final String AES_KEY_FILE = "c:\\aes.key";

private static final char PADDING_CHARACTER = '*';

public static void main(String[] args) {
byte[] encryptResult = encryptAES(addPadding("测试AES192加密算法", 16),
        AES_KEY_LENGTH);
System.out.println(parseByte2HexStr(encryptResult));
byte[] decryptResult = decryptAES(encryptResult, AES_KEY_LENGTH);
String resultStr = byte2String(decryptResult);
System.out.println(noPadding(resultStr, PADDING_CHARACTER));
}

public static byte[] encryptAES(String content, int keySize) {
try {
SecretKeySpec spec = getAESKeySpec(keySize);
Cipher cipher = Cipher.getInstance(AES_ECB_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, spec);
byte[] byteContent = string2Byte(content);
byte[] result = cipher.doFinal(byteContent);
return result;
} catch (Exception e) {
System.out.println("AES加密失败" + e);
}
return null;
}

public static byte[] decryptAES(byte[] content, int keySize) {
try {
SecretKeySpec spec = getAESKeySpec(keySize);
Cipher cipher = Cipher.getInstance(AES_ECB_PADDING);
cipher.init(Cipher.DECRYPT_MODE, spec);
byte[] result = cipher.doFinal(content);
return result;
} catch (Exception e) {
System.out.println("AES解密失败" + e);
}
return null;
}

public static String parseByte2HexStr(byte[] b) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = "0" + hex;
}
sb.append(hex);
}
return sb.toString().toUpperCase();
}

/**
 * 填充字符
 * 
 * @param str
 * @param length
 * @return
 */
private static String addPadding(String str, int length) {
return padding(str, PADDING_CHARACTER, length, 0);
}

private static String padding(String str, char ch, int length, int i) {
if (str == null 
------解决思路----------------------
 str.length() == 0) {
return null;
}
int strLen = string2Byte(str).length;
StringBuffer sb = new StringBuffer();
if (strLen % length == 0) {
String paddingLen = String.valueOf(i);
str = str.substring(0, str.length() - paddingLen.length());
sb.append(str).append(i);
return sb.toString();
} else {
String paddingStr = sb.append(str).append(ch).toString();
return padding(paddingStr, ch, length, i + 1);
}
}

/**
 * 移除填充字符
 * 
 * @param str
 * @param ch
 * @return
 */
private static String noPadding(String str, char ch) {
if (str == null 
------解决思路----------------------
 str.length() == 0) {
return null;
}
int len = str.length();
String subStr = str.substring(str.lastIndexOf(ch) + 1, len);
String resultStr = str.substring(0, len - Integer.parseInt(subStr));
return resultStr;
}

/**
 * 
 * @param keySize
 *            密钥长度
 * @return
 * @throws Exception
 */
private static SecretKeySpec getAESKeySpec(int keySize) throws Exception {
if ((keySize != 128) && (keySize != 192) && (keySize != 256)) {
throw new Exception("加密的keySize错误!");
}
byte[] bytes = new byte[keySize / 8];
File f = new File(AES_KEY_FILE);
if (f.exists()) {
readAESKeyFile(bytes, f);
} else {
bytes = wirteAESKeyFile(keySize, bytes, f);
}
SecretKeySpec spec = new SecretKeySpec(bytes, AES);
return spec;
}

/**
 * 读取密钥文件
 * 
 * @param bytes
 * @param f
 */
private static void readAESKeyFile(byte[] bytes, File f) {
FileInputStream in = null;
try {
in = new FileInputStream(f);
in.read(bytes);
} catch (FileNotFoundException e) {
System.out.println("未找到AES加解密所需的KEY" + e);
} catch (IOException e) {
System.out.println("读取AES加解密所需的KEY失败" + e);
} finally {
closeStream(in, null);
}
}

/**
 * 生成密钥文件
 * 
 * @param keySize
 * @param bytes
 * @param f
 * @return
 */
private static byte[] wirteAESKeyFile(int keySize, byte[] bytes, File f) {
SecretKey key;
KeyGenerator kgen;
FileOutputStream out = null;
try {
kgen = KeyGenerator.getInstance(AES);
kgen.init(keySize);
key = kgen.generateKey();
bytes = key.getEncoded();
out = new FileOutputStream(f);
out.write(bytes);
} catch (NoSuchAlgorithmException e) {
System.out.println("没有该加解密算法" + e);
} catch (FileNotFoundException e) {
System.out.println("未找到AES加解密所需的KEY" + e);
} catch (IOException e) {
System.out.println("生成AES加解密所需的KEY失败" + e);
} finally {
closeStream(null, out);
}
return bytes;
}

private static byte[] string2Byte(String str) {
byte[] b = null;
try {
b = str.getBytes(ENCODING);
} catch (UnsupportedEncodingException e) {
System.out.println("不支持该种编码方式" + e);
}
return b;
}

public static String byte2String(byte[] bytes) {
String str = null;
try {
str = new String(bytes, ENCODING);
} catch (UnsupportedEncodingException e) {
System.out.println("不支持该种编码方式" + e);
}
return str;
}

private static void closeStream(InputStream in, OutputStream out) {
if (in != null) {
try {
in.close();
} catch (IOException e) {
System.out.println("输入流关闭异常" + e);
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
System.out.println("输出流关闭异常" + e);
}
}
}
}