3DES使用密码箱3加密/解密(C#中的原始代码)

问题描述 投票:0回答:1

我在C#中有下一个代码

DESCryptoServiceProvider Crypto = new DESCryptoServiceProvider();
Crypto.BlockSize = 64;
Crypto.FeedbackSize = 8;
Crypto.Mode = CipherMode.ECB;
Crypto.Padding = PaddingMode.None;
Encryptor = Crypto.CreateEncryptor(Encoding.ASCII.GetBytes("key"), Encoding.UTF8.GetBytes("ivkey"));
Decryptor = Crypto.CreateDecryptor(Encoding.ASCII.GetBytes("key"), Encoding.UTF8.GetBytes("ivkey"));

我需要将其传递给Builder C ++(delphi也可以)。我已经可以在我的proyect中编译密码箱3.7库(https://github.com/TurboPack/LockBox3),但是我不确定如何设置不同的参数

TSimpleCodec *cypher;
...
 try {
     cypher=new TSimpleCodec();
     cypher->Reset();
     //HERE is where i need help
     cypher->EncryptStream(ms,ms2);
 } catch (...) {
 }

在delphi / builder上的任何其他工作库也可以。

欢迎任何提示。谢谢,

c# delphi c++builder 3des lockbox-3
1个回答
0
投票

这是使用LockBox 3.7进行AES编码/解码的一个小示例。

void __fastcall TForm1::EncodeDecodeClick(TObject *Sender){
    Codec1->CryptoLibrary = CryptographicLibrary1;
    Codec1->BlockCipherId = "native.AES-256"; // or some other
    Codec1->ChainModeId = "native.CBC";
    Codec1->Password = "secret_key";

    String SecretMessage = "Secret message";
    String EncodedMessage;
    Codec1->EncryptString(SecretMessage, EncodedMessage, TEncoding::UTF8);
    ShowMessage(EncodedMessage);  // e.g. WfmyxjfoGZh3Ky6UoTryvjDsqzM=
    Codec1->DecryptString(SecretMessage, EncodedMessage, TEncoding::UTF8);
    ShowMessage(SecretMessage); // Secret message
}
© www.soinside.com 2019 - 2024. All rights reserved.