androidの文字列のいくつかのトランスコード
3903 ワード
転載自...
①、文字列を暗号化してMD 5、32ビット16進文字列と呼ぶ
②、文字列を暗号化してASCII文字列と呼ぶ
③、ASCII文字列を16進文字列にプログラミングする
転載先:https://www.cnblogs.com/ccddy/p/3965769.html
①、文字列を暗号化してMD 5、32ビット16進文字列と呼ぶ
②、文字列を暗号化してASCII文字列と呼ぶ
③、ASCII文字列を16進文字列にプログラミングする
import java.security.MessageDigest;
public class StringUtils {
public static String replaceUrlWithPlus(String url) {
if (url != null) {
return url.replaceAll("http://(.)*?/", "").replaceAll("[.:/,%?&=]", "+").replaceAll("[+]+", "+");
}
return null;
}
public static String EncodeMD5(String text) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(text.getBytes("US-ASCII"));
byte[] digest = md.digest();
StringBuffer md5 = new StringBuffer();
for (int i = 0; i < digest.length; i++) {
md5.append(Character.forDigit((digest[i] & 0xF0) >> 4, 16));
md5.append(Character.forDigit((digest[i] & 0xF), 16));
}
return md5.toString();
}
public static String EncodeMD5ASCII(String text) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(text.getBytes("US-ASCII"));
byte[] digest = md.digest();
return new String(digest, "US-ASCII");
}
public static String DecodeMD5Hex(String text) throws Exception {
byte[] digest = text.getBytes();
StringBuffer md5 = new StringBuffer();
for (int i = 0; i < digest.length; i++) {
md5.append(Character.forDigit((digest[i] & 0xF0) >> 4, 16));
md5.append(Character.forDigit((digest[i] & 0xF), 16));
}
return md5.toString();
}
}
転載先:https://www.cnblogs.com/ccddy/p/3965769.html