zoukankan      html  css  js  c++  java
  • android之字符串的一些转码

    转载自。。。

        ①、将字符串加密称MD5,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();
        }
    }
  • 相关阅读:
    记录一段QQ关于 UNIGUI 的Session 时间设定
    uniGUI Cannot read property 'remove' of null
    基于kbmMW Configuration Framework 实现配置文件对象化
    每日日报42
    每日日报41
    每日日报40
    解决Ajax无法跳转到其他界面
    每日日报39
    每日日报38
    《软件项目成功之道》阅读笔记01
  • 原文地址:https://www.cnblogs.com/ccddy/p/3965769.html
Copyright © 2011-2022 走看看