如何解密密码 [英] How to decrypt password

查看:73
本文介绍了如何解密密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解密密码我有以下代码的加密密码我想要密码解密c#

How to decrypt password i have Encrypt Password for below code i want password Decrypt in c#

public static string ComputeHash(string plainText, string hashAlgorithm, byte[] saltBytes)
        {
            // If salt is not specified, generate it.
            if (saltBytes == null)
            {
                // Define min and max salt sizes.
                int minSaltSize = 4;
                int maxSaltSize = 8;

                // Generate a random number for the size of the salt.
                Random random = new Random();
                int saltSize = random.Next(minSaltSize, maxSaltSize);

                // Allocate a byte array, which will hold the salt.
                saltBytes = new byte[saltSize];

                // Initialize a random number generator.
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

                // Fill the salt with cryptographically strong byte values.
                rng.GetNonZeroBytes(saltBytes);
            }

            // Convert plain text into a byte array.
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

            // Allocate array, which will hold plain text and salt.
            byte[] plainTextWithSaltBytes =
            new byte[plainTextBytes.Length + saltBytes.Length];

            // Copy plain text bytes into resulting array.
            for (int i = 0; i < plainTextBytes.Length; i++)
                plainTextWithSaltBytes[i] = plainTextBytes[i];

            // Append salt bytes to the resulting array.
            for (int i = 0; i < saltBytes.Length; i++)
                plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];

            HashAlgorithm hash;

            // Make sure hashing algorithm name is specified.
            if (hashAlgorithm == null)
                hashAlgorithm = "";

            // Initialize appropriate hashing algorithm class.
            switch (hashAlgorithm.ToUpper())
            {

                case "SHA384":
                    hash = new SHA384Managed();
                    break;

                case "SHA512":
                    hash = new SHA512Managed();
                    break;

                default:
                    hash = new MD5CryptoServiceProvider();
                    break;
            }

            // Compute hash value of our plain text with appended salt.
            byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

            // Create array which will hold hash and original salt bytes.
            byte[] hashWithSaltBytes = new byte[hashBytes.Length +
            saltBytes.Length];

            // Copy hash bytes into resulting array.
            for (int i = 0; i < hashBytes.Length; i++)
                hashWithSaltBytes[i] = hashBytes[i];

            // Append salt bytes to the result.
            for (int i = 0; i < saltBytes.Length; i++)
                hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];

            // Convert result into a base64-encoded string.
            string hashValue = Convert.ToBase64String(hashWithSaltBytes);

            // Return the result.
            return hashValue;
        }





我的尝试:



如何解密密码我有以下代码的加密密码我想要密码解密c#



What I have tried:

How to decrypt password i have Encrypt Password for below code i want password Decrypt in c#

public static string ComputeHash(string plainText, string hashAlgorithm, byte[] saltBytes)
{
    // If salt is not specified, generate it.
    if (saltBytes == null)
    {
        // Define min and max salt sizes.
        int minSaltSize = 4;
        int maxSaltSize = 8;

        // Generate a random number for the size of the salt.
        Random random = new Random();
        int saltSize = random.Next(minSaltSize, maxSaltSize);

        // Allocate a byte array, which will hold the salt.
        saltBytes = new byte[saltSize];

        // Initialize a random number generator.
        RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

        // Fill the salt with cryptographically strong byte values.
        rng.GetNonZeroBytes(saltBytes);
    }

    // Convert plain text into a byte array.
    byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

    // Allocate array, which will hold plain text and salt.
    byte[] plainTextWithSaltBytes =
    new byte[plainTextBytes.Length + saltBytes.Length];

    // Copy plain text bytes into resulting array.
    for (int i = 0; i < plainTextBytes.Length; i++)
        plainTextWithSaltBytes[i] = plainTextBytes[i];

    // Append salt bytes to the resulting array.
    for (int i = 0; i < saltBytes.Length; i++)
        plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i];

    HashAlgorithm hash;

    // Make sure hashing algorithm name is specified.
    if (hashAlgorithm == null)
        hashAlgorithm = "";

    // Initialize appropriate hashing algorithm class.
    switch (hashAlgorithm.ToUpper())
    {

        case "SHA384":
            hash = new SHA384Managed();
            break;

        case "SHA512":
            hash = new SHA512Managed();
            break;

        default:
            hash = new MD5CryptoServiceProvider();
            break;
    }

    // Compute hash value of our plain text with appended salt.
    byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

    // Create array which will hold hash and original salt bytes.
    byte[] hashWithSaltBytes = new byte[hashBytes.Length +
    saltBytes.Length];

    // Copy hash bytes into resulting array.
    for (int i = 0; i < hashBytes.Length; i++)
        hashWithSaltBytes[i] = hashBytes[i];

    // Append salt bytes to the result.
    for (int i = 0; i < saltBytes.Length; i++)
        hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];

    // Convert result into a base64-encoded string.
    string hashValue = Convert.ToBase64String(hashWithSaltBytes);

    // Return the result.
    return hashValue;
}

推荐答案

首先,SHA不是加密算法 - 它是哈希算法。它们之间的最大区别在于,加密可以通过解密来反转以获得原始输入,而哈希不能 - 它会丢弃信息而您无法从哈希值中获取原始输入。



好​​消息是,这正是你想要做的!散列是处理密码的正确方法 - 你永远不应加密它们,因为这对安全性有害! :笑:

见这里:密码存储:如何要做到这一点。 [ ^ ] - 它解释了如何使用散列值来验证用户。
First off, SHA is not an Encryption algorithm - it's a Hashing algorithm. The big difference between them is that Encryption can be reversed by Decryption to get teh original input back, and Hashing can't - it throws away information and you cannot get the original input back from the hashed value.

The good news is that that is exactly what you want to do! Hashing is the right way to handle passwords - you should never encrypt them as that is bad for security! :laugh:
See here: Password Storage: How to do it.[^] - it explains how to use the hashed value to validate your user.


SHA不是加密算法,因此无法通过它来反转它设计。

SHA is not an encryption algo, thus it can't be reversed it is by design.
引用:

如果不可能在SHA Algoritm中密码解密然后如何解密原始输入中的密码是另一个算法

if not possible Password Decryption in SHA Algoritm then How to Decrypt Password in original input is another Algorithm

唯一的方法是计算每个可能密码的哈希值,直到找到1给出相同哈希码的密码。这是非常强大的力量。

The only method is to calc the hash of every single possible password until you find 1 that give the same hash code. That is brut force.

引用:

我创建了一个应用程序,其中使用密码的哈希算法。但是用户是忘记密码然后管理员在原始输入中发送邮件到用户密码

所以我需要这个时间以解密格式。

i have create one application where use is hash algorithm for password.but user is forget password then admin person which is send mail to user password in original input
so i need this time in decrypted format.

存在其他解决方案。例如,允许用户第二次注册为具有相同电子邮件地址的新用户,然后让管理员在旧帐户中复制密码代码。您可以设置任何其他不涉及解密密码的程序。

Other solutions exist. For example allow the user to register a second time as new user with same Email adress, then have the admin copy the password code in old account. You can device any other procedure that don't involve decrypting the password.


这篇关于如何解密密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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