栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

C#的HttpServerUtility.UrlTokenDecode是否有Java等效项?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C#的HttpServerUtility.UrlTokenDecode是否有Java等效项?

我尝试使用

org.apache.commons.prec.binary.base64
(ctor接受一个参数,说明编码/解码是否是url安全的),但事实证明它的实现方式与UrlTokenEnpre
/ Depre不同。

我最终将C#实现迁移到Java:

 public static byte[] UrlTokenDepre(String input) {     if (input == null)        return new byte[0];    int len = input.length();     if (len < 1)        return new byte[0];    ///////////////////////////////////////////////////////////////////    // Step 1: Calculate the number of padding chars to append to this string.     //         The number of padding chars to append is stored in the last char of the string.    int numPadChars = (int)input.charAt(len - 1) - (int)'0';        if (numPadChars < 0 || numPadChars > 10) return null;    ///////////////////////////////////////////////////////////////////     // Step 2: Create array to store the chars (not including the last char)    //          and the padding chars     char[] base64Chars = new char[len - 1 + numPadChars];    ////////////////////////////////////////////////////////     // Step 3: Copy in the chars. Transform the "-" to "+", and "*" to "/"    for (int iter = 0; iter < len - 1; iter++) {         char c = input.charAt(iter);        switch (c) {  case '-':     base64Chars[iter] = '+';         break;     case '_':     base64Chars[iter] = '/';      break; default:      base64Chars[iter] = c;     break;        }    }    ////////////////////////////////////////////////////////     // Step 4: Add padding chars     for (int iter = len - 1; iter < base64Chars.length; iter++) {        base64Chars[iter] = '=';     }    // Do the actual conversion    String assembledString = String.copyValueOf(base64Chars);    return base64.deprebase64(assembledString);}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470350.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号