Как синхронизировать шифрование между delphi и c #, используя dcpcrypt 3des CFB sha1 - PullRequest
0 голосов
/ 06 сентября 2018

Я использую веб-сервис Delphi xe4, c #.Я пытаюсь синхронизировать шифрование (delphi) с шифрованием (c #) и не удается.Delphi-код с использованием sha1 3des тоже самое с 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;

В чем может быть проблема, помогите пожалуйста.

...