asp.net中的密码加密 [英] password encryption in asp.net

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

问题描述

我想要vb.net中带有asp.net的相应代码.下面是C#代码.请帮助我.我是asp.net的新手

i want the corresponding code in vb.net with asp.net. below is the c# code. plese help me. i am new in asp.net

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Cryptography;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

/// <summary>
/// Summary description for Cryptography
/// </summary>
public class Cryptography
{
    public static RSACryptoServiceProvider rsa;
    public static void AssignParameter()
    {
        const int PROVIDER_RSA_FULL = 1;
        const string CONTAINER_NAME = "SpiderContainer";
        CspParameters cspParams;
        cspParams = new CspParameters(PROVIDER_RSA_FULL);
        cspParams.KeyContainerName = CONTAINER_NAME;
        cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
        cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
        rsa = new RSACryptoServiceProvider(cspParams);
    }
    public static string EncryptData(string data2Encrypt, string path)
    {
        AssignParameter();
        //StreamReader reader = new StreamReader(@"C:\Inetpub\wwwroot\dotnetspiderencryption\publickey.xml");
        StreamReader reader = new StreamReader( path + "/publickey.xml");
        string publicOnlyKeyXML = reader.ReadToEnd();
        rsa.FromXmlString(publicOnlyKeyXML);
        reader.Close();
        //read plaintext, encrypt it to ciphertext	
        byte[] plainbytes =	System.Text.Encoding.UTF8.GetBytes(data2Encrypt);
        byte[] cipherbytes = rsa.Encrypt(plainbytes, false);
        return Convert.ToBase64String(cipherbytes);
    }
    public static void AssignNewKey(string path)
    {
        AssignParameter();
        //provide public and private RSA params	
        StreamWriter writer = new StreamWriter(path + "/privatekey.xml");
        string publicPrivateKeyXML = rsa.ToXmlString(true);
        writer.Write(publicPrivateKeyXML);
        writer.Close();
        //provide public only RSA params	
        writer = new StreamWriter(path + "/publickey.xml");
        string publicOnlyKeyXML = rsa.ToXmlString(false);
        writer.Write(publicOnlyKeyXML);
        writer.Close();
    }
    public static string DecryptData(string data2Decrypt, string path)
    {
        AssignParameter();
        byte[] getpassword = Convert.FromBase64String(data2Decrypt);
        StreamReader reader = new StreamReader(path + "/privatekey.xml");
        string publicPrivateKeyXML = reader.ReadToEnd();
        rsa.FromXmlString(publicPrivateKeyXML);
        reader.Close();
        //read ciphertext, decrypt it to plaintext	
        byte[] plain =	rsa.Decrypt(getpassword,false);
        return System.Text.Encoding.UTF8.GetString(plain);
    }
}

推荐答案

您可以使用免费的在线转换器.看看这个链接,例如:
http://www.developerfusion.com/tools/convert/csharp-to-vb/ [^ ]

There are free online converters that you can use. Have a look at this link for example:
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]

Good luck!


看看这个工具. .NET的代码转换(C# -> VB.NET) [ ^ ]
Have a look at this tool.Code Translation for .NET (C#<->VB.NET)[^]


尝试
http://converter.telerik.com/ [ ^ ]
将在线VB转换为C#或将C#转换为VB
Try
http://converter.telerik.com/[^]
to Convert online VB to C# or C# to VB


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

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