This topic is mainly about Java security, it should be considered a hodgepodge, but not lack of practicality, as a summary, when used can be used as a reference.
1, using BASE64 plus decryption
In Java encryption technology, BASE64 is the simplest and most basic encryption technology. See the following example:
Importjava.io.IOException;ImportDecoder.base64decoder;ImportDecoder.base64encoder; Public classBase64test { Public Static voidMain (string[] args)throwsioexception{String Data= "I am a data that needs to be encrypted"; System.out.println ("Before encryption:" +data); String data1=encryptBASE64 (Data.getbytes ()); System.out.println ("After encryption:" +data1); byte[] Data2 =decryptBASE64 (DATA1); System.out.println ("After decryption:" +NewString (data2)); } Private StaticString encryptBASE64 (byte[] data) { return(NewBase64encoder ()). Encodebuffer (data); } Private Static byte[] decryptBASE64 (String data)throwsioexception{return(NewBase64decoder ()). Decodebuffer (data); }}
Results:
before encryption: I am a need to encrypt the data after encryption: Ztlkx9k7upbq6nkqvnpd3lxeyv2+3q== after decryption: I am a data that needs to be encrypted
The number of strings encrypted with BASE64 is a multiple of 4, a character of two bytes, that is, the string after BASE64 encryption must be a multiple of 8 bytes, if not enough, you need to fill in the back "=" number, so many times you can see the use of BASE64 encrypted characters with "=" end.
Strings that are encrypted with BASE64 will be inserted with a carriage return every 76 characters, so even if the plaintext is long, the printed ciphertext will not be displayed on one line. However, when decrypting, these carriage returns appear insignificant, even if the ciphertext does not contain a carriage return character can also be decrypted normally.