加密串的固定长度 [英] Encrypt string to fixed length

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

问题描述

我要加密的字符串为Base64,字符串输入可以是差分长度(上限为16 charcters),我想在固定长度的加密字符串。

I want to encrypt string to base64, the string input can be in differential length(the limit is 16 charcters), and I want to get the encrypted string in fixed length.

有谁知道做,在.NET框架的方式吗?或者有一种算法来做到这一点?

Does anyone know about the way to do that in .NET framework? or has an algorithm to do that?

推荐答案

如果你正在寻找1单向加密(无需解密),你可以使用SHA1

If you're looking for 1-way encryption (no need to decrypt), you can use SHA1

        string secretKey = "MySecretKey";
        string salt = "123";
        System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
        byte[] preHash = System.Text.Encoding.UTF32.GetBytes(secretKey + salt);
        byte[] hash = sha.ComputeHash(preHash);
        string password = prefix + System.Convert.ToBase64String(hash);

如果你想加密和解密,你很可能使用RSA。

If you want to encrypt and decrypt, you could probably use RSA.

这篇关于加密串的固定长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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