MD5是不可逆算法,用DES加密然后用BASE64对加密后的二进制数据进行编码http://www.javayou.com

解决方案 »

  1.   

    //java.security.MessageDigest alg=java.security.MessageDigest.getInstance("MD5");
          java.security.MessageDigest alga=java.security.MessageDigest.getInstance("SHA-1");
          alga.update(myinfo.getBytes());
          byte[] digesta=alga.digest();      //通过某中方式传给其他人你的信息(myinfo)和摘要(digesta) 对方可以判断是否更改或传输正常
          java.security.MessageDigest algb=java.security.MessageDigest.getInstance("SHA-1");
          algb.update(myinfo.getBytes());
          if (algb.isEqual(digesta,algb.digest())) {
             System.out.println("信息检查正常");
           }
           else
            {
              System.out.println("摘要不相同");
             }
      

  2.   

    可以考虑http://community.csdn.net/Expert/topic/3270/3270409.xml?temp=.5324671所回复的恺撒算法思想
      

  3.   

    to:ntzls(三星堆) 謝謝你的代碼,但是為什麼每次 "Hello World"加密後的字符串會不一樣呢,另外卻不能將加密後的字符串重新轉成為 "Hello World"?---------------------------------------------------------------------------
    package natoni;import java.util.Random;public class SimpleEncoder {

    private static Random random = new Random();

    public static void main(String[] args){
    String s = "hello world";
    System.out.println(s+'\n');
    byte[] key = getRandomKey(5);
    byte[] s1 = encrypt(key,s.getBytes());
    System.out.println(new String(s1)+'\n');
    byte[] s2 = decrypt(key,s1);
    System.out.println(new String(s2)+'\n');
    }

    public static byte[] getRandomKey(int length) {
    if(length <= 0){
    throw new IllegalArgumentException();
    }
    int rand, index=0;
    byte[] result = new byte[length];
    for(int i=0; i<(length/5); i++){
    rand = random.nextInt();
    for(int j=0; j<5; j++) {
    result[index++] = (byte)(rand&63);
    rand >>= 6;
    }
    }
    rand = random.nextInt();
    for(int i=0; i<(length%5); i++) {
    result[index++] = (byte)(rand&63);
    rand >>= 6;
    }
    return result;
    }

    public static byte[] encrypt(byte[] key, byte[] b) {
    if(key==null || b==null){
    throw new IllegalArgumentException();
    }
    int index = 0;
    byte[] result = (byte[])b.clone();
    for(int i=0; i<(b.length/key.length); i++){
    for(int j=0; j<key.length; j++){
    result[index++] += key[j];
    }
    }
    for(int i=0; i<(b.length%key.length); i++){
    result[index++] += key[i]; 
    }
    return result;
    }

    public static byte[] decrypt(byte[] key, byte[] b) {
    if(key==null || b==null){
    throw new IllegalArgumentException();
    }
    int index = 0;
    byte[] result = (byte[])b.clone();
    for(int i=0; i<(b.length/key.length); i++){
    for(int j=0; j<key.length; j++){
    result[index++] -= key[j];
    }
    }
    for(int i=0; i<(b.length%key.length); i++){
    result[index++] -= key[i]; 
    }
    return result;
    }
    }
      

  4.   

    这个问题简单,看看加解密api吧
      

  5.   

    public static javax.crypto.SecretKey genDESKey(byte[] key_byte) throws
            Exception
        {
            SecretKey k = null;
            k = new SecretKeySpec(key_byte, "DESede");
            return k;
        }    public static byte[] desDecrypt(javax.crypto.SecretKey key, byte[] crypt) throws
            Exception
        {
            javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(
                "DESede");
            cipher.init(javax.crypto.Cipher.DECRYPT_MODE, key);
            return cipher.doFinal(crypt);
        }    public static byte[] desEncrypt(javax.crypto.SecretKey key, byte[] src) throws
            Exception
        {
            javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(
                "DESede");
            cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, key);
            return cipher.doFinal(src);
        }
      

  6.   

    加密後的字符串會不一樣呢程序中演示的是随机密码。byte[] key = getRandomKey(5);
      

  7.   

    to: ntzls(三星堆)我是想對加密後的字符串進行解密,這樣就可以得到原來的字符串了
      

  8.   

    有了加密时的byte[] key 不就可以解密吗?
      

  9.   

    ./    .--...
                                                  .-------- 0    .--
                                                 /                 .......
                                                '                  ..
                                                 '........            ----
                                                          .          --..
                                                           .   .---..   -
                                       分  o               .  '     -.
                                         分               /   '
                                                         / ' ' '
                                       \-分--/....... . '  ' '  '
                                        \ __/ -      - -'  '  ' '
                                                        '  '  ' '
                                         o              '   ' ' '
                                                        '   '  '
                                                         -..'.----------.
                                                            I   ----------
                                                     /////////.