如何使用dcpcrypt 3des CFB sha1在delphi和c#之间同步加密

时间:2018-09-06 20:51:05

标签: c# delphi sha1 3des

我正在使用c#Web服务Delphi xe4。我正在尝试将加密(delphi)同步到加密(c#)并失败。 使用Sha1 3des的Delphi代码与C#相同 我尝试了一切

Delphi代码输出: Nv9eZPY6

DCP_3des1 := TDCP_3Des.Create(self);
    with DCP_3des1 do    
    begin      
      Id := 24;    
      Algorithm := '3DES';    
      MaxKeySize := 192;    
      BlockSize := 64;    
      CipherMode := cmCFB8bit;    
    end;

    DCP_3des1.InitStr('Medisoft', TDCP_sha1);    
    DCP_3des1.SetIV('12345678');    
    DCP_3des1.Reset;    
    s := DCP_3des1.EncryptString('123asd');    
    Label1.Caption := s;

c#代码输出: FYH + tyCp
我使用了Chilkat,但可能还有其他代码。

Chilkat.Crypt2 crypt = new Chilkat.Crypt2();
bool success = crypt.UnlockComponent("Anything for 30-day trial");
if (success != true)
{
Console.WriteLine(crypt.LastErrorText);
return;
}

//  Specify 3DES for the encryption algorithm:
crypt.CryptAlgorithm = "3des";
crypt.HashAlgorithm = "sha1";

//  CipherMode may be "ecb" or "cbc"
crypt.CipherMode = "cfb";

//  KeyLength must be 192.  3DES is technically 168-bits;
//  the most-significant bit of each key byte is a parity bit,
//  so we must indicate a KeyLength of 192, which includes
//  the parity bits.
crypt.KeyLength = 192;

//  The padding scheme determines the contents of the bytes
//  that are added to pad the result to a multiple of the
//  encryption algorithm's block size.  3DES has a block
//  size of 8 bytes, so encrypted output is always
//  a multiple of 8.
crypt.PaddingScheme = 0;

//  EncodingMode specifies the encoding of the output for
//  encryption, and the input for decryption.
//  It may be "hex", "url", "base64", or "quoted-printable".
crypt.EncodingMode = "base64";

//  An initialization vector is required if using CBC or CFB modes.
//  ECB mode does not use an IV.
//  The length of the IV is equal to the algorithm's block size.
//  It is NOT equal to the length of the key.
crypt.SetEncodedIV("12345678", "ascii");

//  The secret key must equal the size of the key.  For
//  3DES, the key must be 24 bytes (i.e. 192-bits).
crypt.SetEncodedKey("Medisoft", "ascii");

//  Encrypt a string...
//  The input string is 44 ANSI characters (i.e. 44 bytes), so
//  the output should be 48 bytes (a multiple of 8).
//  Because the output is a hex string, it should
//  be 96 characters long (2 chars per byte).
string encStr = crypt.EncryptStringENC("123asd");
textBox2.Text = encStr;

//  Now decrypt:
string decStr = crypt.DecryptStringENC(encStr);
textBox4.Text = decStr;

有什么问题,请帮忙。

0 个答案:

没有答案