首页
社区
课程
招聘
[求助].Net反编译转Delphi
发表于: 2015-11-12 19:56 4962

[求助].Net反编译转Delphi

2015-11-12 19:56
4962

Private Function Encrypt(pToEncrypt As String, sKey As String) As String
			Dim dESCryptoServiceProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
			Dim bytes As Byte() = Encoding.[Default].GetBytes(pToEncrypt)
			dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(sKey)
			dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(sKey)
			Dim memoryStream As MemoryStream = New MemoryStream()
			Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, dESCryptoServiceProvider.CreateEncryptor(), CryptoStreamMode.Write)
			cryptoStream.Write(bytes, 0, bytes.Length)
			cryptoStream.FlushFinalBlock()
			Dim stringBuilder As StringBuilder = New StringBuilder()
			Dim array As Byte() = memoryStream.ToArray()
			For i As Integer = 0 To array.Length - 1
				Dim b As Byte = array(i)
				stringBuilder.AppendFormat("{0:X2}", b)
			Next
			stringBuilder.ToString()
			Return stringBuilder.ToString()
		End Function


Private Function Decrypt(pToDecrypt As String, sKey As String) As String
			Dim dESCryptoServiceProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider()
			Dim array As Byte() = New Byte(pToDecrypt.Length / 2 - 1) {}
			For i As Integer = 0 To pToDecrypt.Length / 2 - 1
				Dim num As Integer = Convert.ToInt32(pToDecrypt.Substring(i * 2, 2), 16)
				array(i) = CByte(num)
			Next
			dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(sKey)
			dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(sKey)
			Dim memoryStream As MemoryStream = New MemoryStream()
			Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write)
			cryptoStream.Write(array, 0, array.Length)
			cryptoStream.FlushFinalBlock()
			Dim stringBuilder As StringBuilder = New StringBuilder()
			Return Encoding.[Default].GetString(memoryStream.ToArray())
		End Function



上面的加解密函数,是ILSpy反编译出来的,,,不会转Delphi,,特求助帮忙转下,,谢谢

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 242
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
顶起来~!
2015-11-13 08:27
0
雪    币: 242
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
网上找的源代码,,谁帮我转至Delphi,,,或者用C++写一个,谢谢

public string Encrypt(string stringToEncrypt, string sKey)
    {
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(stringToEncrypt);
        des.Key = ASCIIEncoding.UTF8.GetBytes(sKey);
        des.IV = ASCIIEncoding.UTF8.GetBytes(sKey);
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();
        StringBuilder ret = new StringBuilder();
        foreach (byte b in ms.ToArray())
        {
            ret.AppendFormat("{0:X2}", b);
        }
        ret.ToString();
        return ret.ToString();
    }
    public string Decrypt(string stringToDecrypt, string sKey)
    {
        DESCryptoServiceProvider des = new DESCryptoServiceProvider();
        byte[] inputByteArray = new byte[stringToDecrypt.Length / 2];
        for (int x = 0; x < stringToDecrypt.Length / 2; x++)
        {
            int i = (Convert.ToInt32(stringToDecrypt.Substring(x * 2, 2), 16));
            inputByteArray[x] = (byte)i;
        }
        des.Key = ASCIIEncoding.UTF8.GetBytes(sKey);
        des.IV = ASCIIEncoding.UTF8.GetBytes(sKey);
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
        cs.Write(inputByteArray, 0, inputByteArray.Length);
        cs.FlushFinalBlock();
        StringBuilder ret = new StringBuilder();
        return System.Text.Encoding.Default.GetString(ms.ToArray());
    }
 
 
//
 
public sealed class DESEncrypt
    ...{
        private DESEncrypt()
        ...{
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        private static string key = "zhoufoxcn";

        /**//// <summary>
        /// 对称加密解密的密钥
        /// </summary>
        public static string Key
        ...{
            get
            ...{
                return key;
            }
            set
            ...{
                key = value;
            }
        }

        /**//// <summary>
        /// DES加密
        /// </summary>
        /// <param name="encryptString"></param>
        /// <returns></returns>
        public static string DesEncrypt(string encryptString)
        ...{
            byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
            byte[] keyIV = keyBytes;
            byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            MemoryStream mStream = new MemoryStream();
            CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
            cStream.Write(inputByteArray, 0, inputByteArray.Length);
            cStream.FlushFinalBlock();
            return Convert.ToBase64String(mStream.ToArray());
        }

        /**//// <summary>
        /// DES解密
        /// </summary>
        /// <param name="decryptString"></param>
        /// <returns></returns>
        public static string DesDecrypt(string decryptString)
        ...{
            byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
            byte[] keyIV = keyBytes;
            byte[] inputByteArray = Convert.FromBase64String(decryptString);
            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            MemoryStream mStream = new MemoryStream();
            CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
            cStream.Write(inputByteArray, 0, inputByteArray.Length);
            cStream.FlushFinalBlock();
            return Encoding.UTF8.GetString(mStream.ToArray());
        }
    }
2015-11-13 09:28
0
雪    币: 602
活跃值: (45)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
一毛不拔啊
2015-11-13 10:39
0
雪    币: 79
活跃值: (35)
能力值: ( LV2,RANK:150 )
在线值:
发帖
回帖
粉丝
5
其实你就是想做DES加解密,C#是调用.Net类库做的,所以非常方便。
Delphi不可能照搬使用。

要么你直接用C#,要么就另外找Delphi的DES加解密。
2015-11-20 11:14
0
雪    币: 71
活跃值: (930)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
自己用 xor 做个把, C#和 delphi 蛋疼, 之前 找了 好久 都找不到 , 还不如 自己写个
2015-11-20 12:01
0
游客
登录 | 注册 方可回帖
返回
//