AES解密(超额字母,字符,符号/缺少字母,字符,符号)

时间:2014-02-06 18:15:13

标签: java encryption aes

我们正在创建一个加密和解密.java文件的系统,特别是代码。 现在它已100%运行,但我们在解密阶段遇到了一些问题。 在我们的系统中,加密文件将其文件扩展名从.java更改为.aes。 然后,在解密.aes文件以返回.java的部分中,它不会返回到EXACT FORM。有符号/字母/字符出现。

实施例: 原始的.java文件:system.out.print 加密:4567jhgcvbhjkljh 解密:system.ou“/// nshujjprint

下面的

:解密部分的代码片段

public static void main(String[] args){
    AES aes = null;
    String password = "timothyjamesorti";
    String toDecipher = "   //Decrypt Rounds 9 through 1\n" + 
    "for(int i = 9; i>0; i--){\n" +
    "   invShiftRows();\n" +
    "   subInvBytes();\n" +
    "   addRoundKey(i);\n" +
    "   invMixCols();\n" +
    "}\n" +
    "\n" +
    "//Decrypt a partial round 0\n" +
    "invShiftRows();\n" +
    "subInvBytes();\n" +
    "addRoundKey(0);\n" +
    "\n" +
    "mode = PLAIN; //Change the mode.\n" +
    "}\n" +
    "\n" +
    "}";

    String outputString = "";
    List<String> strings = new ArrayList<>();
    int len = toDecipher.length();
    int spaces = 16 - (len % 16);
    if(spaces > 0){
        for(int i = 0; i < spaces; i++){
            toDecipher += " ";
        }
    }
    System.out.println("toDecipherLength: " + toDecipher.length());

    while(toDecipher.length() >= 16){
        String candidate = toDecipher.substring(0, 16);
        toDecipher = toDecipher.substring(16, toDecipher.length());
        aes = new AES(password, candidate);
        strings.add(aes.ASE_Cipher_loop());
    }

    /**
     * 
     NmðìÀÁÝbÏȼ| ¦É¥Øsã7S:BÌ#g#asÈ GXD{ØIpÍà[g¥©jvÅ+72Vp¥Nè Ì2& ÞrK¸0qê0Ûî­QþAøÈgø¥îó.ÚÅ2Vüîýák>ëq*:(äÇf°®²KçS­³Jú+<Ëkã}&èf33äMï/eÏ)­¶Z¶~¬¡Yï`ývvL¥­¶:WÓ¯ÿ´ÁÿÅ4<péÊÑàV~å0vÓ]Âz

(d¬          * /

    String deciper = "NmðìÀÁÝbÏȼ| ¦É¥Øsã7S:BÌ#g#asÈ GXD{ØIpÍà[g¥©jvÅ+72Vp¥Nè Ì2& ÞrK¸0qê0Ûî­QþAøÈgø¥îó.ÚÅ2Vüîýák>ëq*:(äÇf°®²KçS­³Jú+<Ëkã}&èf33äMï/eÏ)­¶Z¶~¬¡Yï`ývvL¥­¶:WÓ¯ÿ´ÁÿÅ4<péÊÑàV~å0vÓ]Âz(d¬";
    strings = new ArrayList<>();
    len = deciper.length();
    spaces = 16 - (len % 16);
    if(spaces > 0){
        for(int i = 0; i < spaces; i++){
            deciper += " ";
        }
    }
    outputString = "";
    System.out.println("toDecipherLength: " + deciper.length());
    String decrypted = "";
    while(deciper.length() >=16){
        String candidate = deciper.substring(0, 16);
        deciper = deciper.substring(16, deciper.length());
        aes = new AES(password, candidate);
        decrypted += aes.ASE_Decipher_loop();
    }

    /*for(String string : strings){
        aes = new AES(password, string);
        outputString += aes.ASE_Decipher_loop();
    }*/
    decrypted = decrypted.substring(0, decrypted.length() - spaces);
    System.out.println(decrypted);

    SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");  

    try  
    {  
        Date date = format.parse("2013-01-2013"); 
        System.out.println("date: " + date);
    }  

    catch(ParseException e)  
    {  
    e.printStackTrace();   
    }  
}

0 个答案:

没有答案
相关问题