vb.net中的加密函数 vb加密程序-成都快上网建站

vb.net中的加密函数 vb加密程序

VB中如何编写一个加密程序?

编写一个加密软件,要求将源文件按字节逐位倒排序加密法加密。

目前创新互联公司已为上千的企业提供了网站建设、域名、网络空间、网站托管、服务器托管、企业网站设计、蓝田网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

字节逐位倒排序加密法是以比特为单位的换位加密方法,用vb实现的具体算法是:

(1) 以二进制模式打开源文件;

(2) 从源文件第i位读取一个字节,假设为字母“a”,得到“a”的ascii值为65;

(3) 将65转换成八位二进制串为“01000001”;

(4) 将“01000001”按字节逐位倒排序得另一个八位二进制串“10000010”;

(5) 将“10000010”转换成十进制再写回源文件第i位置,完成一个字节的加密;

(6) 重复(2)、(3)、(4)和(5),直到所有字节加密结束。

为了使程序模块化,我们用函数过程bytetobin完成将字节型数据转换成二进制串(其实质就是将十进制数转换成八位二进制串);用函数过程bintobyte将二进制串转换成字节型数据(实质是将八位二进制串转换成十进制数):用函数过程reverse将八位二进制串逐位倒排序。具体程序如下:

function bytetobin(m as byte) as string ' 将字节型数据转换成八位二进制字符串

dim c$

c$ = ""

do while m 0

r = m mod 2

m = m \ 2

c$ = r c$

loop

c$ = right("00000000" c$, 8)

bytetobin = c$

end function

function reverse(m as string) as string ' 将八位二进制字符串颠倒顺序

dim i%, x$

x = ""

for i = 1 to 8

x = mid(m, i, 1) x

next i

reverse = x

end function

function bintobyte(m as string) as byte ' 将八位二进制串转换成十进制

dim x as string * 1, y%, z%

z = 0

for i = 1 to 8

x = mid(m, i, 1)

y = x * 2 ^ (8 - i)

z = z + y

next i

bintobyte = z

end function

private sub command1_click()

dim x as byte, i%, fname$

fname = inputbox("请输入要加密的文件名!注意加上路径名:")

if dir(fname) = "" then

msgbox "文件不存在!"

exit sub

end if

open fname for binary as #1 ' 以二进制访问模式打开待加密文件

for i = 1 to lof(1) ' lof函数是求文件长度的内部函数

get #1, i, x ' 取出第i个字节

x = bintobyte(reverse(bytetobin(x))) ' 这里调用了三个自定义函数

put #1, i, x ' 将加密后的这个字节写回到文件原位置

next i

close

msgbox "任务完成!"

end sub

VB.NET开发的软件,大家一般都是怎么加密的

网上有很多专业的加密教程

最适合小开发者的软件加密方式就是下面这个

获取硬件信息和个人注册时的姓名手机号等一系列信息,通过预先设定好的加密函数进行散列加密,生成一个只有本人本机能使用的序列号,软件正版授权的时候用同样的方式生成序列号进行比对,一样则通过

vb 加密字符串的方法

Private Sub Command1_Click()   '加密

Dim b() As Byte, i As Long

Open "d:\1.txt" For Binary As #1

b = InputB(LOF(1), #1)

Close #1

Randomize

For i = 0 To UBound(b) - 1

b(i) = b(i) Xor b(i + 1)

Next

b(i) = b(i) Xor 93

Open "d:\2.txt" For Binary As #1

Put #1, , b

Close #1

MsgBox "1.txt已加密为2.txt"

End Sub

Private Sub Command2_Click()   '解密

Dim b() As Byte, i As Long

Open "d:\2.txt" For Binary As #1

b = InputB(LOF(1), #1)

Close #1

Randomize

b(UBound(b)) = b(UBound(b)) Xor 93

For i = UBound(b) - 1 To 0 Step -1

b(i) = b(i) Xor b(i + 1)

Next

Open "d:\3.txt" For Binary As #1

Put #1, , b

Close #1

MsgBox "2.txt已解密为3.txt"

End Sub

1.txt加密后存为2.txt

2.txt解密后存为3.txt

请注意,这个程序是可以加密解密任何文件的(包括exe可执行文件),不单单是文本文件。

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.net中的加密函数 vb加密程序
转载源于:http://kswjz.com/article/dojcjgi.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流