IDEA算法,比如我有  变量 byte[] a,  byte[] b;  需要调用IDEA算法,将这两个byte[] 处理后返回一个byte[].         byte[] encryptdata = idea.IdeaEncrypt(a, b, true);
         byte[] decryptdata = idea.IdeaEncrypt(a, b, false);这是我从网上查的IDEA源代码,这里的true 和false 有什么区别???   谁能提供给我一个IDEA的算法? 可以直接输入a,b后直接返回一个byte[]类型的IDEA方法。我对IDEA的算法不是很了解。期待你的献策……

解决方案 »

  1.   

    上http://www.bouncycastle.org/ 下载那个bouncy castle crypto API, 把 
    它的jar包加进来以后, 用以下一段很短的代码就可以实现IDEA加密了, good luck! import org.bouncycastle.crypto.BufferedBlockCipher; 
    import org.bouncycastle.crypto.CipherParameters; 
    import org.bouncycastle.crypto.params.KeyParameter; 
    import org.bouncycastle.crypto.engines.IDEAEngine; 
    import org.bouncycastle.util.encoders.Base64; 
    /** 
    * User: wooce 
    * Date: 2003-9-10 
    * Time: 10:36:05 
    */ 
    public class IDEAEncrypt { 
    private BufferedBlockCipher cipher; 
    private String key; public IDEAEncrypt(String key) { 
    cipher = new BufferedBlockCipher(new IDEAEngine()); 
    this.key = key; 
    } public byte[] encrypt(String str) { 
    CipherParameters param = new KeyParameter(key.getBytes()); 
    cipher.init(true, param); int len = str.length(); 
    if (str.length() % 8 > 0) 
    len -= str.length() % 8; 
    byte[] cleartext = new byte[str.length()]; 
    System.arraycopy(str.getBytes(), 0, cleartext, 0, str.length()); 
    byte[] out = new byte[cleartext.length]; if (len > 0) 
    cipher.processBytes(cleartext, 0, cleartext.length, out, 0); 
    if (str.length() % 8 > 0) { 
    int j = 0; 
    for (int i = str.length() - 1; j < str.length() % 8; i--) { 
    j++; 
    out[i] = (byte) (cleartext[i] ^ 197); 


    byte[] finalOut = Base64.encode(out); 
    return finalOut; 

      

  2.   

    http://zhidao.baidu.com/question/52560554.html