you try try
ClassMethod AESEncode(str As %String, key)
{
Set text=$ZCONVERT(str,"O","UTF8")
set len=$l(text)
if (16-len#16)'=0{
for ii=1:1:(16-len#16){
set text=text_$c(16-len#16)
}
}else{
for ii=1:1:16{
set text=text_$c(16)
}
}
s stream=##class(%GlobalCharacterStream).%New()
d stream.Write(text)
s textstr=""
while 'stream.AtEnd{
set subtx=stream.Read(16)
Set textstr =textstr_$system.Encryption.AESEncode(subtx,key)
}
Set ret=$SYSTEM.Encryption.Base64Encode(textstr)
s ret = $replace(ret,$c(13,10),"")
q ret
}
/**
* 解密
*/
ClassMethod AESDecode(str As %String, key)
{
s ret = ##class(%SYSTEM.Encryption).Base64Decode(str)
s ret = ##class(%SYSTEM.Encryption).AESDecode(ret, key)
s ret = $zcvt(ret, "I", "UTF8")
set len=$l(ret)
set lastch=$e(ret,len,len)
set pos=0
for index=1:1:16 {
if $c(index)=lastch{
set pos=index
quit
}
}
s ret = $e(ret,1,len-pos)
q ret
}
- Log in to post comments