加密字符串从Delphi到C# [英] Encrypted string From Delphi to C#

查看:103
本文介绍了加密字符串从Delphi到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Delphi加密汇编中的Cipher1 3.0 Part I解密一个在Delphi中加密的c#中的一个字符串。
我使用TCipher_Rijndael。



我加密的字符串是:this-is-a-test-example



password:pass

加密值是:iKBC8kX4ZEk4A1pCj6jwEegqjpxhqw ==



当我尝试解密这个在c#i recive错误:数据解密是无效的。



有没有人有同样的问题,有什么解决方案?



这里是c#中的解密方法:

  public static byte [] Decrypt(byte [] cipherData,
byte [] Key,byte [] IV)
{

MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
CryptoStream cs = new CryptoStream(ms,
alg.CreateDecryptor(),CryptoStreamMode.Write);
cs.Write(cipherData,0,cipherData.Length);
cs.Close();
byte [] decryptptedData = ms.ToArray();
return decryptptedData;
}

这里是Delphi中的加密代码:

 与TCipher_Rijndael.Create('pass',nil)do 
begin
memo2.lines.add(CodeString('this-is- a-test-example',paEncode,fmtDEFAULT));
免费;
结束

谢谢。

解决方案

您需要确定该值被加密的所有细节:


  1. 什么块密码操作模式被使用?欧洲央行往往是默认值。

  2. 什么 padding方案被使用?在你的情况下也许没有填充。

  3. 密钥派生从密码?也许 PBKDF2 或只是一个 MD5 哈希。

  4. 什么是初始化向量?请注意,只有一些密码模式需要一个。

  5. 输出是如何编码的?它似乎是 Base64 编码。

只有一旦你确切知道它是如何被加密的,你可以反过来进行正确的解密。您可能想尝试发布更多代码或有关如何加密的详细信息。那么有人可能能够确定你需要如何去解密它。我看过这个场景与未知数之前,我设法猜测细节找到答案。我尝试了几种常见的加密字符串方式,但是如果没有更多的细节,我无法轻松解密。


i am trying to decrypt one string in c# encrypted in Delphi with Cipher1 3.0, Part I from Delphi Encryption Compendium. I use TCipher_Rijndael.

string that i encrypt is : this-is-a-test-example

password: pass

encrypted values is : iKBC8kX4ZEk4A1pCj6jwEegqjpxhqw==

When i try to decrypt this in c# i recive error: Length of the data to decrypt is invalid.

Did anyone have the same problem, and what is a solution?

Here is a decrypt method in c#:

public static byte[] Decrypt(byte[] cipherData,
                                byte[] Key, byte[] IV)
    {

        MemoryStream ms = new MemoryStream();  
        Rijndael alg = Rijndael.Create();      
        alg.Key = Key;
        alg.IV = IV;
        CryptoStream cs = new CryptoStream(ms,
            alg.CreateDecryptor(), CryptoStreamMode.Write);           
        cs.Write(cipherData, 0, cipherData.Length);    
        cs.Close();
        byte[] decryptedData = ms.ToArray();
        return decryptedData;
    }

and here is encrypt code in Delphi:

with TCipher_Rijndael.Create('pass',  nil) do
      begin
        memo2.lines.add ( CodeString( 'this-is-a-test-example' , paEncode, fmtDEFAULT));
        Free;
      end;

Thanks.

解决方案

You need to determine all of the details of how that value was encrypted:

  1. What block cipher mode of operation was used? ECB tends to be a default.
  2. What padding scheme was used? Perhaps no padding in your case.
  3. How was the key derived from the password? Perhaps with PBKDF2 or simply a MD5 hash.
  4. What was the initialization vector? Note that only some cipher modes require one.
  5. How was the output encoded? It appears to be Base64 encoding for you.

Only once you know exactly how it was encrypted can you reverse the process to properly decrypt it. You might want to try posting more code or details about how it was encrypted. Then someone might be able to determine how you need to go about decrypting it. I've seen this scenario with unknowns before and I managed to guess the details to find the answer. I tried a few common ways with your encrypted string, but I can't easily decrypt it without more details.

这篇关于加密字符串从Delphi到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆