Android Base64 encryption and decryption, androidbase64
// The encrypted incoming data is of the byte type. Instead of converting the original data to binary data using the decode method, you can use str. getBytes () to String str = "Hello! "; // Here the encode method is used. The returned data is byte-type encrypted data. You can convert it to String-type String strBase64 = new String (Base64.encode (str. getBytes (), Base64.DEFAULT); Log. I ("Test", "encode >>>" + strBase64); // here encodeToString directly returns String-type encrypted data String enToStr = Base64.encodeToString (str. getBytes (), Base64.DEFAULT); Log. I ("Test", "encodeToString >>>" + enToStr); // decrypts the base64 encrypted data. I ("Test", "decode >>>" + new String (Base64.decode (strBase64.getBytes (), Base64.DEFAULT )));
The java base64 decryption garbled code is as follows:
Private String getPictureString () {String upload = ""; try {FileInputStream in = new FileInputStream (fileName); byte [] ba = new byte [in. available ()]; in. read (ba); in. close (); upload = new String (android. util. base64.encode (ba, android. util. base64.DEFAULT);} catch (FileNotFoundException e) {LogUtil. e (e. getMessage (), e);} catch (IOException e) {LogUtil. e (e. getMessage (), e);} return upload ;}
This is encrypted.
Decryption is
Encode to decode
Upload = new String (android. util. Base64.decode (ba,
Android. util. Base64.DEFAULT ));
Encryption and decryption issues such as base64 and md5
Base64 is not used for encryption. It is used to prevent "bytes" from being converted into numbers that can display characters.
For example, 0-32 control characters, spaces, and tabs cannot be printed on paper. base64 only uses uppercase and lowercase numbers for punctuation.
Data can be printed on paper and carried on traditional flat media.
Md5 is A hash function that extracts data features and outputs irreversible hash values. It is used to represent information A without exposing information. It is not directly used to encrypt files.