TSimpleCodec.Begin_EncryptMemory - Wrong mode

ⅰ亾dé卋堺 提交于 2021-01-29 07:12:43

问题


I get TSimpleCodec.Begin_EncryptMemory - Wrong mode exception wile executing the following code. Is it something wrong?

FLibrary := TCryptographicLibrary.Create(Self);
FCodec := TCodec.Create(Self);
FCodec.CryptoLibrary := FLibrary;
FCodec.BlockCipherId := 'native.AES-256';
FCodec.ChainModeId := 'native.ECB';
FCodec.Password := 'password';
plain := 'The plain text';
FCodec.EncryptString(plain, astr);
FCodec.DecryptString(dec, astr);

回答1:


When initialising the codec by run-time code, you need to set the StreamCipherId. Insert the following line just before setting the BlockCipherId.

 FCodec.StreamCipherId := BlockCipher_ProgId;

You don't need to do this if you are setting up the codec with design-time values. It's much easier to do at design-time. Just set the published properties as required.

The demo program for Delphi 2010, gives an example in methods TmfmLockbox3_Demo.FormCreate() and TmfmLockbox3_Demo.actCustomBlockEncryptExecute() .

Also read the on-line help about it.

As a general hint, if you just look at the demo program and/or read the on-line help, you will rarely need to come to StackOverflow. If there are any short-comings in the documentation, please post some constructive actionable suggestions on the LockBox forums to improve the documentation (demos + on-line help).



来源:https://stackoverflow.com/questions/10130659/tsimplecodec-begin-encryptmemory-wrong-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!