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文件中的連接字元串將不能夠正常解密。