为什么编码给出不同的结果?

时间:2016-06-06 13:04:36

标签: encoding base64

这是我的字符串

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class TestJFrame extends JFrame {

    public TestJFrame() {

        setTitle("A test application");
        setPreferredSize(new Dimension(500, 500));
        setBackground(Color.black);
        setResizable(false);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        JPanel testPanel = new JPanel();
        testPanel.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                super.keyPressed(e);
                switch(e.getKeyCode()) {
                    case KeyEvent.VK_UP:
                        System.out.println("Test");
                }
            }
        });
        add(testPanel);
        testPanel.setFocusable(true);
        testPanel.requestFocusInWindow();

        pack();
        setVisible(true);
    }

    public static void main(String[] args) {
        new TestJFrame();
    }
}

我正在使用此代码

<Auth uid="" tid="" ver="" txn="" lk=""><Meta udc="" fdc="" idc="" pip="" lot="P" lov=""/><Skey ci="">03ec063e6a932b12130090c7112a15ba30bb5c0db05b9a0fd22dbd8d33fd61ea1fd1dca544905d5c77c31783376a0b94bf6136ecf9e10dbc5cb3cd09d335c4b4c114b49c5124306a3ea9c0ce124d8da4135de27a99d60085d77a11c2769207bd700fd61d80867e043557713d9dc030fec6949e1049811285e55a561644e12ead734dc61d3caa89b313879da8339efe8163bbcc750cc7901a9fb7353920e544bc851a76e07206a357d34123fb7703440d793063f8bfc54293522266f8e12a059dadfd8822d3585f230265094501d8014ab45b896928ef03062e4745a31d5e2be9b0c1dd61c95fa89dc8e1d66ab34b438a49aaa055055a2ce680719d3e62e3cefa</Skey><Data type="">55c8623b6b26ce63b0cc4fd7333d7ef47cc02e4bb27e4fef879092f487698bcc575b571c5ca834d3b6dd23ab8c73877ecfc243427d34239c9276a0187ab4e1a13559172c57de0a9aa66f8497ecc757449889d9e00cc958963838eedbccf5f6c5d4d426cba12869b2ee530e5b32d08e1123839b348efc51999a384fc46629d2beb75638650ec6a041698ac1411a306362174c8d38687832095b27f36c3f59586fbf73370e79488b03157bd5e12305140c29f1fc4d8500157e93ec71c5b829f7d23f7fcb5079fa9d21c90bc8ac2c043b7c221e45eb2ea1ba14091cdc614a5a1591153072bcbdcfaab8b517f9bfdcf66bfdef1ba1b7455edd37c2b5a08ce299f16219a6398368c1b08aa236c93f1a6949f0e8aada425c7fe3a318ae507e3ec1e6108b66c5dff1872071c15fca0e0ffd3986b2fecd0105b1667526b1760c742a2812b46f0a6775447bddf4387574d16ff85418bce76328496042d6b4d8fde3fac902580a3eb0f4ebd12b0dc653fc29eee45fcb183a1a352a58b464385e5596203c9e1273ab5b1e48a98059614e8924f25aa506aaf3328fba4cf218ecd242fa68976b73ff75c92f1bc96e434463804ad34772184f7e1e1d6d8a7a61f33e354b60c35735488a3ca6dd57ac544d5ed77338bb73178d62bbcde6e6e1997c87b1801823fa904e318f2e33cafa99b9b7d8bbe25d039296d4a22228196a00a89ce27e690ed29c81db23dc683ef6bcd8a1bb77dc8b95725b1a874fc9059aa91d55787357ffea77c2bb71863370e7cdf96efc4f3f975168c1a74861d6f776632e1cc2e0c40a247f734db07847d2eb4d6bcbbe57bb8b7c61f44c1ff1571cb70c9acf650412205325a4a005ad286b705943b4f9cc160e268cf3174cc5031f9e4b47f6df8f52bc6fc42ba1bcef4fb56a12591e7d3eedec0124c2ed300215c263010925a1c56161376019d8de44a062f81f667818f90b269b61482453ff469529c91c0bb5771ffae848a6dbbe57816a6bde84cdaf576f1279a65b1dc3dc92ed3bdf80ccbde1373f6b098f28c33e905a39138b83713bdccc45b1bf05a76be308e3f16bef17655df0ef45dbf4b661e8ecae5cb819e751d1f9bd80adcda398dd7044c7e283aa88f7c174</Data><Hmac>4c4a58555a484c6a4651486d344a6b586f586131536555573373594a30757768593046345435644c336677576a2b65682b686e416e6d52634878383751767632</Hmac></Auth>

,输出

    public String encode(String orig)
    {
    byte[] encoded = Base64.encodeBase64(orig.getBytes());      



    System.out.println("Original String: " + orig );

    String s=new String(encoded);

    System.out.println("Base64 Encoded String :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jPjRjNGE1ODU1NWE0ODRjNmE0NjUxNDg2ZDM0NGE2YjU4NmY1ODYxMzE1MzY1NTU1NzMzNzM1OTRhMzA3NTc3Njg1OTMwNDYzNDU0MzU2NDRjMzM2Njc3NTc2YTJiNjU2ODJiNjg2ZTQxNmU2ZDUyNjM0ODc4MzgzNzUxNzY3NjMyPC9IbWFjPjwvQXV0aD4=

最后的数字已更改 那是为什么?

1 个答案:

答案 0 :(得分:2)

这是因为你在第二个字符串的末尾有额外的"\n"。运行此命令可以很容易看出:

echo "your base 64 encoded string"|base64 -d|hexdump -C

在linux shell中