vbnet字符串加密解密
❶ vb如何加密、解密文本
大致有21种加密/解密算法源代码,和50多种种压缩/解压的算法源代码文件
http://www.codefans.net/soft/2055.shtml
❷ VB.net实现简单的加密解密--->该怎么写代码
已在VB上调试通过:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j As Integer
Dim et(TextBox1.Text.Length) As Char
j = 0
For i = 0 To TextBox1.Text.Length - 1
et(i) = Chr(AscW(TextBox1.Text.Chars(i)) + AscW(TextBox2.Text.Chars(j)))
j = j + 1
If j >= TextBox2.Text.Length Then j = 0
Next
TextBox1.Text = et
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, j As Integer
Dim et(TextBox1.Text.Length) As Char
j = 0
For i = 0 To TextBox1.Text.Length - 1
et(i) = Chr(AscW(TextBox1.Text.Chars(i)) - AscW(TextBox2.Text.Chars(j)))
j = j + 1
If j >= TextBox2.Text.Length Then j = 0
Next
TextBox1.Text = et
End Sub
❸ .net技术:对文本框中输入的字符串进行加密、解密。。
using System; using System.Security; using System.Security.Cryptography; using System.IO; using System.Text; using System.Threading; namespace TRIP3DES { ///<summary> /// Class1 的摘要说明。 ///</summary>public class dllEncrypt { //密钥 private const string sKey = ""; //矢量,矢量可以为空 private const string sIV = "qcDY6X+aPLw="; //构造一个对称算法 private SymmetricAlgorithm mCSP = new (); public dllEncrypt(){} #region public string EncryptString(string Value) ///<summary> /// 加密字符串 ///</summary> ///<param name="Value">输入的字符串</param> ///<returns>加密后的字符串</returns>public string EncryptString(string Value) { ICryptoTransform ct; MemoryStream ms; CryptoStream cs; byte[] byt; mCSP.Key = Convert.FromBase64String(sKey); mCSP.IV = Convert.FromBase64String(sIV); //指定加密的运算模式 mCSP.Mode = System.Security.Cryptography.CipherMode.ECB; //获取或设置加密算法的填充模式 mCSP.Padding = System.Security.Cryptography.PaddingMode.PKCS7; ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV); byt = Encoding.UTF8.GetBytes(Value); ms = new MemoryStream(); cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Convert.ToBase64String(ms.ToArray()); } #endregion #region public string DecryptString(string Value) ///<summary> /// 解密字符串 ///</summary> ///<param name="Value">加过密的字符串</param> ///<returns>解密后的字符串</returns>public string DecryptString(string Value) { ICryptoTransform ct; MemoryStream ms; CryptoStream cs; byte[] byt; mCSP.Key = Convert.FromBase64String(sKey); mCSP.IV = Convert.FromBase64String(sIV); mCSP.Mode = System.Security.Cryptography.CipherMode.ECB; mCSP.Padding = System.Security.Cryptography.PaddingMode.PKCS7; ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV); byt = Convert.FromBase64String(Value); ms = new MemoryStream(); cs = new CryptoStream(ms, ct, CryptoStreamMode.Write); cs.Write(byt, 0, byt.Length); cs.FlushFinalBlock(); cs.Close(); return Encoding.UTF8.GetString(ms.ToArray()); } #endregion } }
❹ asp.net(VB)加密解密源代码
答案如下 (经本人测试,肯定是可以用的……)
'-----------------------------------------
' 随机选8个字节既为密钥也为初始向量
Private Shared KEY_64() As Byte = {42, 162, 39, 156, 78, 4, 218, 32}
Private Shared IV_64() As Byte = {55, 113, 346, 79, 36, 99, 167, 3}
'------------------------------------------------
'标准的DES加密
Public Function Encrypt(ByVal value As String) As String
If value <> "" Then
Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider
Dim ms As MemoryStream = New MemoryStream
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write)
Dim sw As StreamWriter = New StreamWriter(cs)
sw.Write(value)
sw.Flush()
cs.FlushFinalBlock()
ms.Flush()
'--------------------------------------
'再转换为一个字符串
Return Convert.ToBase64String(ms.GetBuffer(), 0, ms.Length)
Else
Return ""
End If
End Function
'----------------------------------
'标准的DES解密
Public Function Decrypt(ByVal value As String) As String
If value <> "" Then
Dim cryptoProvider As DESCryptoServiceProvider = New DESCryptoServiceProvider
'---------------------------------------
'从字符串转换为字节组
Dim buffer As Byte() = Convert.FromBase64String(value)
Dim ms As MemoryStream = New MemoryStream(buffer)
Dim cs As CryptoStream = New CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read)
Dim sr As StreamReader = New StreamReader(cs)
Return sr.ReadToEnd()
Else
Return ""
End If
End Function
❺ 加密解密高手进!VB.NET 谁能给一个MD5或其他的加密算法
这个是我之前写的。在需要时调用即可。
Public Shared Function Encrypt(ByVal Text As String, ByVal sKey As String) As String
Dim provider As New DESCryptoServiceProvider()
Dim bytes As Byte() = Encoding.[Default].GetBytes(Text)
provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.(sKey, "md5").Substring(0, 8))
provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.(sKey, "md5").Substring(0, 8))
Dim stream As New MemoryStream()
Dim stream2 As New CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write)
stream2.Write(bytes, 0, bytes.Length)
stream2.FlushFinalBlock()
Dim builder As New StringBuilder()
For Each num As Byte In stream.ToArray()
builder.AppendFormat("{0:X2}", num)
Next
Return builder.ToString()
End Function
希望能帮到你
❻ 用VB.net编写一个加密解密软件
"采用DES算法"这个说法不明确,首先是使用多少位的DES进行加密,通常是128位或192位,其次是,要先把主密钥转化成散列,才能供DES进行加密,转化的方法是什么没有明确,通常是md5,所以有的银行卡说是128位md5 3DS就是指用md5转换主密钥散列,用DES进行加密,但是DES本身是64位(包含校验码),2DES是128位,3DES是192位,但是没有2DES的叫法,所以128位、192位统称3DES
要完整的md5+3DS实例,需要100分以上,要不到我的空间中查找相关的文章
❼ vb.net中实现rsa加密解密 急!急!
我觉得你的并不是RSA加密解密算法。
在.net的有一个System.Security.Cryptography的命名空间,里面有一RSACryptoServiceProvider的类用来对byte进行RSA加密解密。
具体例子如下:
using System;
using System.Security.Cryptography;
using System.Text;
class RSACSPSample
{
static void Main()
{
try
{
//Create a UnicodeEncoder to convert between byte array and string.
UnicodeEncoding ByteConverter = new UnicodeEncoding();
//Create byte arrays to hold original, encrypted, and decrypted data.
byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt");
byte[] encryptedData;
byte[] decryptedData;
//Create a new instance of RSACryptoServiceProvider to generate
//public and private key data.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Pass the data to ENCRYPT, the public key information
//(using RSACryptoServiceProvider.ExportParameters(false),
//and a boolean flag specifying no OAEP padding.
encryptedData = RSAEncrypt(dataToEncrypt,RSA.ExportParameters(false), false);
//Pass the data to DECRYPT, the private key information
//(using RSACryptoServiceProvider.ExportParameters(true),
//and a boolean flag specifying no OAEP padding.
decryptedData = RSADecrypt(encryptedData,RSA.ExportParameters(true), false);
//Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData));
}
catch(ArgumentNullException)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine("Encryption failed.");
}
}
static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding)
{
try
{
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Import the RSA Key information. This only needs
//toinclude the public key information.
RSA.ImportParameters(RSAKeyInfo);
//Encrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
return RSA.Encrypt(DataToEncrypt, DoOAEPPadding);
}
//Catch and display a CryptographicException
//to the console.
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo,bool DoOAEPPadding)
{
try
{
//Create a new instance of RSACryptoServiceProvider.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Import the RSA Key information. This needs
//to include the private key information.
RSA.ImportParameters(RSAKeyInfo);
//Decrypt the passed byte array and specify OAEP padding.
//OAEP padding is only available on Microsoft Windows XP or
//later.
return RSA.Decrypt(DataToDecrypt, DoOAEPPadding);
}
//Catch and display a CryptographicException
//to the console.
catch(CryptographicException e)
{
Console.WriteLine(e.ToString());
return null;
}
}
}
[Visual Basic]
Try
'Create a new RSACryptoServiceProvider object.
Dim RSA As New RSACryptoServiceProvider()
'Export the key information to an RSAParameters object.
'Pass false to export the public key information or pass
'true to export public and private key information.
Dim RSAParams As RSAParameters = RSA.ExportParameters(False)
Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine(e.Message)
End Try
[C#]
try
{
//Create a new RSACryptoServiceProvider object.
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
//Export the key information to an RSAParameters object.
//Pass false to export the public key information or pass
//true to export public and private key information.
RSAParameters RSAParams = RSA.ExportParameters(false);
}
catch(CryptographicException e)
{
//Catch this exception in case the encryption did
//not succeed.
Console.WriteLine(e.Message);
}
❽ ASP.NET 对字符串加密解密 只有小写字母和数字
这是我现在用的。 private static byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; //密钥向量 /// <summary> /// 加密 /// </summary> /// <param name="EncryptString">待加密的字符串</param> /// <param name="EncryptKey">加密密钥</param> /// <returns>加密成功返回加密后的字符串,失败返回源串</returns> public static string Encrypt(string EncryptString, string EncryptKey) { byte[] byKey = null; byKey = System.Text.Encoding.UTF8.GetBytes(EncryptKey.Substring(0, 8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(EncryptString); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); return Convert.ToBase64String(ms.ToArray()); } /// <summary> /// 解密 /// </summary> /// <param name="EncryptString">待解密的字符串</param> /// <param name="EncryptKey">解密密钥</param> /// <returns>解密成功返回解密后的字符串,失败返源串</returns> public static string Decrypt(string EncryptString, string EncryptKey) { byte[] byKey = null; byte[] inputByteArray = new Byte[EncryptString.Length]; try { byKey = System.Text.Encoding.UTF8.GetBytes(EncryptKey.Substring(0, 8)); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); inputByteArray = Convert.FromBase64String(EncryptString); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); System.Text.Encoding encoding = new System.Text.UTF8Encoding(); return encoding.GetString(ms.ToArray()); } catch { return ""; } }
❾ 简单VB.NET加密与解密
Private Function myEncrypt(ByVal Code As String) As String
Dim Result As String = ""
Dim CurrentChar As Char
For i As Integer = 0 To Code.Length - 1
CurrentChar = Code.Substring(i, 1)
Select Case Code.Substring(i, 1)
Case "Z"
Result &= "a"
Case "z"
Result &= "A"
Case Else
Result &= Chr(Asc(CurrentChar) + 1)
End Select
Next
Return Result
End Function
'vb.net 2005 调试通过
❿ ASP.net如何对数据库连接字符串进行加密和解密
给方法:开始--->运行,输入cmd,接着输入以下内容
加密:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef "connectionStrings" "你的Web项目路径"
解密:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pdf "connectionStrings" "你的Web项目路径"
.NET为版本的路径自行修改,其中connectionStrings连接字符串的名称。
需要注意的是,加密过程中使用了一个基于本机的密钥,这意味着解密过程必须在同一台计算机上完成。如果是将加密后的Web.config文件移动到其它计算机上,那么Web.config文件中的连接字符串将不能够正常解密。