Reprinted: How to perform Base64 encoding and decoding in Java

xiaoxiao2021-03-06  71

// Take s Base64 encoding

Public static string getBase64 (String s) {

IF (s == null) Return NULL;

Return (New Sun.misc.Base64Encoder ()). Encode (s.getbytes ());

}

// Decod the base64 encoded string S

Public static string getFromBase64 (String s) {

IF (s == null) Return NULL;

Base64decoder decoder = new base64decoder ();

Try {

Byte [] b = decoder.decodebuffer (s);

Return New String (b);

} catch (exception e) {

Return NULL;

}

}

转载请注明原文地址:https://www.9cbs.com/read-88135.html

New Post(0)