java achieve base64 encryption and decryption

Base64 is one of the most common network for the transmission of 8Bit encoding bytecode, Base64 is based on 64 printable characters to binary data representation.

Base64 is generally used for transferring binary data under the HTTP protocol, since the HTTP protocol is text, the HTTP protocol in the transmission of binary data to binary data to character data. However, direct conversion is not acceptable. Because the transmission network transmission can only printable characters. What is a printable character? In the ASCII code specified, 0 to 31,128 characters which belong to the control characters 33, 32 and 127 belong to the 95 printable characters characters, that is to say that the network transmission can only transmit 95 characters, the character is not within this range It can not be transferred. So how can we transfer the other characters? One way is to use Base64.

Need to import BASE64Decoder.jar package


encryption:

            String xmlInfo ="需要加密的内容";
            byte[] bytes=xmlInfo.getBytes();
            String base64keyString =new BASE64Encoder().encodeBuffer(bytes);

Decryption:

        String b = "需要解密内容";
        byte[] bt = (new BASE64Decoder()).decodeBuffer(b); 
        String key=new String(bt); 

 

Guess you like

Origin blog.csdn.net/qq_39404258/article/details/91046471