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();
        }
    }
  • 相关阅读:
    ansible常用模块及参数(1)
    ansible搭建wordpress,安装nfs和rsync
    ElasticSearch 集群
    kibana数据操作
    ElasticSearch 交互使用
    Elasticsearch的基础安装
    Elasticsearch的简介
    redis数据审计
    redis数据迁移
    redis集群节点添加与删除
  • 原文地址:https://www.cnblogs.com/ccddy/p/3965769.html
Copyright © 2011-2022 走看看