Created
August 3, 2018 16:05
-
-
Save YacheLee/bc9d2462ebce2253e0a996141086aec7 to your computer and use it in GitHub Desktop.
String to md5 to base64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.codec.binary.Base64; | |
import org.apache.commons.codec.digest.DigestUtils; | |
import java.security.MessageDigest; | |
/** | |
* Created by Scott on 2018/8/4. | |
*/ | |
public class Main { | |
public static void main(String[] args){ | |
String text = "Storage Transfer MD5 Test\n"; | |
byte[] md5 = getMd5(text); | |
String base64 = getBase64Encode(md5); | |
System.out.println(base64); | |
} | |
public static byte[] getMd5(String text){ | |
MessageDigest md5Digest = DigestUtils.getMd5Digest(); | |
return md5Digest.digest(text.getBytes()); | |
} | |
public static String getBase64Encode(byte[] md5){ | |
return Base64.encodeBase64String(md5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment