在asp.net中加密和解密 [英] Encrypt and Decrypt in asp .net

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

问题描述

有人可以给我代码加密和解密一个字符串在asp .net

Can someone give me the code to Encrypt and Decrypt a string in asp .net

推荐答案

你好Sameer,



我建议你尝试自己的加密技术,因为C#有更多的加密方法。



Hi Sameer,

I would suggest you to try your own encryption technology since C# has more number of encryption methodology.

private string encodeStr =
            @"!#


%&'()* +, - 。/ 0123456789:;< =>?@ ABCDEFGHIJKLMNOPQRSTUVWXYZ [\] ^ _`abcdefghijklmnopqrstuvwxyz {|}〜;

private string decodeStr =
@ @ ABCDEFGHIJKLMNO0123456789:;< =>?pqrstuvwxyz {|}〜!#
%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; private string decodeStr = @"@ABCDEFGHIJKLMNO0123456789:;<=>?pqrstuvwxyz{|}~!#


%& amp ;()* +, - /`ABCDEFGHIJKLMNOPQRSTUVWXYZ [\] ^ _


protected string encodeString( string rawText)
{
string cipherText = string .Empty;
foreach char rawChar in rawText)
{
cipherText + = encodeStr.ElementAt(decodeStr.IndexOf(rawChar));
}
return cipherText;
}

// 自定义解密方法
protected string decodeString( string cipherText)
{
string rawText = string .Empty;
foreach char cipherChar in cipherText)
{
rawText + = decodeStr.ElementAt(encodeStr.IndexOf(cipherChar));
}
return rawText;
}
%&'()*+,-./`abcdefghijklmnoPQRSTUVWXYZ[\]^_"; protected string encodeString(string rawText) { string cipherText = string.Empty; foreach (char rawChar in rawText) { cipherText += encodeStr.ElementAt(decodeStr.IndexOf(rawChar)); } return cipherText; } //Custom Decryption method protected string decodeString(string cipherText) { string rawText = string.Empty; foreach (char cipherChar in cipherText) { rawText += decodeStr.ElementAt(encodeStr.IndexOf(cipherChar)); } return rawText; }





函数调用:

encodeString(输入要加密的字符串);

decodeString(输入要解密的字符串);



好​​的,如果你不是准备尝试自己的加密方法,看看这里 [ ^ ]和使用.NET加密/解密 [ ^ ]



Function call:
encodeString("input String to encrypt");
decodeString("input String to decrypt");

Ok if you not ready to try your own encryption methods, have a look at here[^]andEncryption/Decryption with .NET[^]


这篇关于在asp.net中加密和解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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