紧急知道此密码使用哪个加密的人吗? [英] URGENT | ANYONE WHO KNOWS WHICH ENCRYPTION IS USED IN THIS CODE?

查看:57
本文介绍了紧急知道此密码使用哪个加密的人吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我们面临着一个严峻的问题,我们的研发人员现在对JAVA做了很多事情,我们已经加密了发送到服务器的数据,以下是我们客户提供的代码,但是他们没有还是个主意.

Right now, we are faced with a severe issue, our R&D guy do now much about JAVA, we have encrypt the data send to server, below is the code provided by our customer, but they have no idea either.

希望有人知道,请您与我们联系吗?

Hope anyone who knows about it, would you please contact us?

非常感谢您的帮助.预先感谢.

Your help is quite appreciated. Thanks in advance.

静态只读字符串PasswordHash ="P @@ Sw0rdkhallew";
       静态只读字符串SaltKey ="S @ LT& KEYNEW";
       静态只读字符串VIKey ="@ 1B2c3D4e5F6g7H @ 12";

       公共静态字符串Encrypt(string plainText)
        {
            byte [] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            byte [] keyBytes = new Rfc2898DeriveBytes(PasswordHash,Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256/8);
            var symmetricKey = new RijndaelManaged(){模式= CipherMode.CBC,填充= PaddingMode.Zeros};
            var cryptoor = symmetricKey.CreateEncryptor(keyBytes,Encoding.ASCII.GetBytes(VIKey));

            byte [] cipherTextBytes;

           使用(var memoryStream = new MemoryStream())
            {
               使用(var cryptoStream = new CryptoStream(memoryStream,encryptor,CryptoStreamMode.Write))
                {
                    cryptoStream.Write(plainTextBytes,0,plainTextBytes.Length);
                    cryptoStream.FlushFinalBlock();
                    cipherTextBytes = memoryStream.ToArray();
                    cryptoStream.Close();
                }
                memoryStream.Close();
            }
           返回Convert.ToBase64String(cipherTextBytes);
        }
       公共静态字符串Decrypt(string encryptionText)
        {
            byte [] cipherTextBytes = Convert.FromBase64String(encryptedText);
  byte [] keyBytes =新的Rfc2898DeriveBytes(PasswordHash,Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256/8);
            var symmetricKey = new RijndaelManaged(){模式= CipherMode.CBC,填充= PaddingMode.None};

            var Decryptor = symmetricKey.CreateDecryptor(keyBytes,Encoding.ASCII.GetBytes(VIKey));
            var memoryStream =新的MemoryStream(cipherTextBytes);
            var cryptoStream =新的CryptoStream(memoryStream,解密器,CryptoStreamMode.Read);
            byte [] plainTextBytes =新的byte [cipherTextBytes.Length];

            int unlockedByteCount = cryptoStream.Read(plainTextBytes,0,plainTextBytes.Length);
            memoryStream.Close();
            cryptoStream.Close();
           返回Encoding.UTF8.GetString(plainTextBytes,0,unlockedByteCount).TrimEnd("\ 0&"; ToCharArray());
        }

static readonly string PasswordHash = "P@@Sw0rdkhallew";
        static readonly string SaltKey = "S@LT&KEYNEW";
        static readonly string VIKey = "@1B2c3D4e5F6g7H@12";

        public static string Encrypt(string plainText)
        {
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
            var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));

            byte[] cipherTextBytes;

            using (var memoryStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                    cryptoStream.FlushFinalBlock();
                    cipherTextBytes = memoryStream.ToArray();
                    cryptoStream.Close();
                }
                memoryStream.Close();
            }
            return Convert.ToBase64String(cipherTextBytes);
        }
        public static string Decrypt(string encryptedText)
        {
            byte[] cipherTextBytes = Convert.FromBase64String(encryptedText);
 byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
            var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };

            var decryptor = symmetricKey.CreateDecryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
            var memoryStream = new MemoryStream(cipherTextBytes);
            var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
            byte[] plainTextBytes = new byte[cipherTextBytes.Length];

            int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
            memoryStream.Close();
            cryptoStream.Close();
            return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount).TrimEnd("\0".ToCharArray());
        }

推荐答案

您拥有的是AES.

What you have there is AES.

更准确地说,这是 AES-256 (当今最常用的算法).

To be more precise, this is Rijndael which is the winner of the competition for selecting the AES algorithm (so basically it is AES with a little more freedom in selecting the key and block size). When you use it with the default constructor this is actually AES-256 (the most commonly used algorithm nowadays).

这里是MSDN文档的链接: https://msdn.microsoft.com/zh-CN/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx

Here is a link to the MSDN documentation: https://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged(v=vs.110).aspx



这篇关于紧急知道此密码使用哪个加密的人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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