189 8069 5689

vb.net加解密函数,vb加密程序

简单VB.NET加密与解密

Private Function myEncrypt(ByVal Code As String) As String

成都创新互联主营金坛网站建设的网络公司,主营网站建设方案,成都App制作,金坛h5小程序定制开发搭建,金坛网站营销推广欢迎金坛等地区企业咨询

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 调试通过

用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);

}

vb加解密

最简单的设置一个公共变量Code和Key,前者用于存原密码,后者用于存密钥,自定义一个加密函数trans,用于转换Code和Key并显示在text2当中,解密时判定输入的密钥与Key是否符合,如果符合就把Code显示出来。也就是说,这个加密函数只是用于加密转换时,在解密的时候,可以不用它而直接读取Code变量。代码如下:

Dim Code As String, Key As String

Private Sub Command1_Click() '这是加密过程,加密的同时把密码与密钥存入变量Code和Key中

Label2.Caption = "加密后的密码"

Code = Text1.Text

Key = Text3.Text

Text2.Text = trans(Key) trans(Code)

End Sub

Private Sub Command2_Click() '这是解密过程

If Text3.Text Key Then

MsgBox "密钥错误,请重新输入"

Else

MsgBox "原密码是:" Code

End If

End Sub

Private Function trans(s As String) As String '这是加密函数

Dim ch As String

For i = 1 To Len(s)

If Mid(s, i, 1) Like "[A-Z]" Then

ch = ch Chr(155 - Asc(Mid(s, i, 1)))

ElseIf Mid(s, i, 1) Like "[a-z]" Then

ch = ch Chr(219 - Asc(Mid(s, i, 1)))

Else

ch = ch Mid(s, i, 1)

End If

Next

trans = ch

End Function

Private Sub Form_Load() '这是所有用到的控件

Label1.Caption = "密码"

Label2.Caption = "加密后的密码"

Label3.Caption = "密钥"

Command1.Caption = "加密"

Command2.Caption = "解密"

End Sub

补充:我测试没问题。Text2中是加密后的密文,解密时会先判定用户在Text3中所输入的密钥是否与Key变量中保存的密钥相同,如果相同的话才会显示原来的密码。如果出错的话,请检查一下这8个控件,3个Text,3个Label,2个Command,你可以新建一个程序,然后在窗体上放上这8个控件,都用默认属性,然后把代码复制过去,再运行一下试试。


新闻名称:vb.net加解密函数,vb加密程序
转载来于:http://jkwzsj.com/article/hdpecc.html

其他资讯