Android Base64 encryption and decryption, androidbase64

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.