c builder xe6 md5 加密算法 base64 url 编码 -尊龙游戏旗舰厅官网
xe6 md5 加密算法
delphi
function md5(const texto: string): string; varidmd5: tidhashmessagedigest5; beginidmd5 := tidhashmessagedigest5.create;tryresult := idmd5.hashstringashex(texto);finallyidmd5.free;end; end;
c builder #include
texto是汉字有bug,
中国:ea03fcb8c47822bce772cf6c07d0ebbb
北京:ea03fcb8c47822bce772cf6c07d0ebbb
这2个串是相等的啊!!,难道xe6的hashstringashex方法有问题?
最终原因是加上参数indytextencoding_utf8()就可以了。字符编码不正确。
- base64
xe7:move base64 function to system.netencoding.hpp
soap::encddecd::encodestring默认是unicodestring,汉字也是unicode再进行编码。
xe6:encodestring默认是ansistring,汉字也是按ascii码进行b64编码的。
所以xe6、xe7对汉字的b64编码不一样。
在xe7里如果用旧的ascii编码方式,可以调用ansistring __fastcall encodebase64(const void * input, int size)函数实现。 string ustring = memo1->text;ansistring as = ansistring(ustring);memo2->text = soap::encddecd::encodebase64(as.c_str(), as.length());
xe里没有idbase64decoder控件了。
delphi 自带了 base64 编解码的单元,叫 encddecd,这名字很拗口而且不直观,估计这是一直很少人关注和知道的原因。
berlin,xe7 base64,2016.10.8
xe7中对encode重载了3种方法。
int __fastcall encode(tstream* input, tstream* output)/* overload */; dynamicarray
#include
memo2->text = tnetencoding::base64->encode(memo1->text);
memo1->text = tnetencoding::base64->decode(memo2->text);
to encode:
bytes: tbytes;base64 :string; bytes := tencoding.utf8.getbytes(str); base64 := tnetencoding.base64.encodebytestostring(bytes);
use string type
b64:= tnetencoding.base64.encode(astr);
to decode:
bytes := tnetencoding.base64.decodestringtobytes(base64); str := tencoding.utf8.getstring(bytes);
c
tbytes bytes;//tbytedynarray bytes;
tnetencoding::base64->encodebytestostring(&bytes[0], bytes.high);
soap.encddecd.pas
xe 自带的 md5 单元 messagedigest_5.pas
这个单元提供两套四个公开函数:
对流的编解码:
procedure encodestream(input, output: tstream); // 编码
procedure decodestream(input, output: tstream); // 解码
// 对字符串的编解码:
function encodestring(const input: string): string; // 编码
function decodestring(const input: string): string; // 解码
这几个函数在帮助中没有。应该不算是标准库中的函数。
c builder
#include
soap::encddecd::encodestring( edtkl->text);
string es=soap::encddecd::encodestring("ee");
soap::encddecd::encodestring(es);
http://codeverge.com/embarcadero.delphi.tools/indy-tidhashmessagedigest5-changed-f/1061390
根据rfc822规定,每76个字符,还需要加上一个回车换行
如果不用换行符,自己创建类,用maxint
tbase64encoding *b64e=new tbase64encoding(maxint);
mmobase->text = b64e->encodebytestostring(&bta[0], bta.high);
delete b64e;
new unit for web encoding and decoding
the rtl provides a new unit, system.netencoding, that provides encoding and decoding features for base64, html, and url.
the following table shows how methods from previous versions of rad studio map to methods in system.netencoding:
httpencode、urlencode、url编码
hz=httpencode( "查询功能");//解决在中文汉字编码url地址乱码的问题
比如tidhttp.get(url,stream);这个url里含有汉字需要转换一下
xe6xe7
soap.encddecd.encodebase64 | tnetencoding.base64.encodebytestostring |
soap.encddecd.decodebase64 | tnetencoding.base64.decodestringtobytes |
soap.encddecd.encodestream | tnetencoding.base64.encode |
soap.encddecd.decodestream | tnetencoding.base64.decode |
web.httpapp.htmlencode | tnetencoding.html.encode |
web.httpapp.htmldecode | tnetencoding.html.decode |
web.httpapp.httpencode | tnetencoding.url.encode |
web.httpapp.httpdecode | tnetencoding.url.decode |
总结
以上是尊龙游戏旗舰厅官网为你收集整理的c builder xe6 md5 加密算法 base64 url 编码的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: html学习笔记2—列表与清单
- 下一篇: