boom2008 2023-02-27 10:38 采纳率: 0%
浏览 16

C#转DELPHI 代码怎么转??

C#代码:


public static string Enc(string data)
{
System.Text.Encoding unicode = System.Text.Encoding.Unicode;
byte[] rgbKey = new byte[] {1,2,3,4,5,6,7,8};
byte[] rgbIV = new byte[] {1,2,3,4,5,6,7,8};
System.Security.Cryptography.DESCryptoServiceProvider dESCryptoServiceProvider = new System.Security.Cryptography.DESCryptoServiceProvider();
System.Security.Cryptography.ICryptoTransform cryptoTransform = dESCryptoServiceProvider.CreateEncryptor(rgbKey, rgbIV);
byte[] bytes = unicode.GetBytes(data);
byte[] array = cryptoTransform.TransformFinalBlock(bytes, 0, bytes.Length);
result = System.Convert.ToBase64String(array, 0, array.Length);
}
  • 写回答

1条回答 默认 最新

  • Web Security Loop 2023-02-27 10:45
    关注
    
    function Enc(data: string): string;
    var
      unicode: System.Text.Encoding;
      rgbKey, rgbIV, bytes, array_: TBytes;
      dESCryptoServiceProvider: System.Security.Cryptography.DESCryptoServiceProvider;
      cryptoTransform: System.Security.Cryptography.ICryptoTransform;
    begin
      unicode := System.Text.Encoding.Unicode;
      rgbKey := TBytes.Create(1, 2, 3, 4, 5, 6, 7, 8);
      rgbIV := TBytes.Create(1, 2, 3, 4, 5, 6, 7, 8);
      dESCryptoServiceProvider := System.Security.Cryptography.DESCryptoServiceProvider.Create;
      cryptoTransform := dESCryptoServiceProvider.CreateEncryptor(rgbKey, rgbIV);
      bytes := unicode.GetBytes(data);
      SetLength(array_, Length(bytes));
      cryptoTransform.TransformFinalBlock(bytes[0], 0, Length(bytes), array_[0], 0);
      Result := System.Convert.ToBase64String(array_);
    end;
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 2月27日