I want to use AESEncode encryption, but it prompts a MAXSTRING error. How to solve it?
I want to use AESEncode encryption, but it prompts a MAXSTRING error. How to solve it?
I want to use AESEncode encryption, but it prompts a MAXSTRING error. How to solve it?
Can you provide a simple sample code to reproduce the error?
{
s str = $zcvt(str, "O", "UTF8")
s paddingLen = 16 - ($length(str) # 16)
s list = $lb(1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f")
s paddingStr= "0" _ $lg(list, paddingLen)
s padding = ..Repeat($c($zhex(paddingStr)) ,paddingLen)
s ret = str _ padding
s ret = ##class(%SYSTEM.Encryption).AESEncode(ret, key)
s ret = ##class(%SYSTEM.Encryption).Base64Encode(ret)
q ret
}
What product/version are you using?
USER>w $zv
Cache for Windows (x86-64) 2016.2 (Build 736U) Fri Sep 30 2016 11:46:02 EDT
I'm sorry, I don't have a system that old to check/test.
The oldest I have is 2018 and there AESEncode() and AESDecode() are deprecated (use AESCBCEncrypt() and AESCBCDecrypt() instead).
Are AESCBCEncrypt() and AESCBCDecrypt() implemented in version 2016?
And AESCBCEncryptStream(), AESCBCDecryptStream()?
AESCBCEncrypt cannot satisfy AESEncode ECB. Is there an AESECBEncryptStream method?
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
}