从int到短字符串的双向加密

Tho*_*ock 1 .net c# asp.net passwords cryptography

我正在构建一个小型的Web应用程序,我们的客户可以在其中更新有关其公司的一些详细信息.客户目前没有登录名/密码,我们不想验证他们的注册,所以我们想给他们一个自动生成的密码/密钥来登录网站.

我们计划加密他们的customerId并将其交给客户,以便他可以在webapp上输入该密钥,以便我们将密钥解密为他的ID.

大约有1万名客户,他们并没有收到任何电子邮件,因此有些人会收到一封带有URL和代码的信件.这意味着客户必须输入代码,因此代码不能超过8个字符(最好是6个字符).

这是一个空模板:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int passwordLength = 6;
            int customerId = 12345;
            string encrypted = Crypter.Encrypt(customerId, "secretKey", passwordLength);
            if (customerId == Crypter.Decrypt(encrypted, "secretKey"))
            {
                Console.WriteLine("It worked! Well done!");
            }
        }

    }

    public static class Crypter
    {
        public static string Encrypt(int input, string key, int passwordLength)
        {
            string encryptedString = "";
            //do encrypt stuffz here

            return encryptedString;
        }
        public static int Decrypt(string encryoted, string key)
        {
            int decrypted = 0;
            //do decrypt stuffz here

            return decrypted;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

=>任何人都可以链接到我有关如何做到这一点的更多信息?

我不是在寻找"PLZ发送给我的代码",但如果有人已经做过这样的话,请随意分享.

提前感谢您提供任何信息.

Meh*_*ari 8

不要将您的密码基于用户ID.而是为每个客户生成一个随机的6个字符的字符串,并将其存储在数据库中.它不容易找到实际的算法.

  • 删除元音或预览随机字符串(或两者),以确保您不会丢失任何客户,因为您为他们分配了一个讨厌的单词作为他们的密码.据推测,一旦他们通过URL验证,你也会让他们选择一个id /密码 - 否则它将是非常不友好的用户. (3认同)