扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
需要激活的是vs,vb是vs里的集成模板工具
创新互联公司专业为企业提供无极网站建设、无极做网站、无极网站设计、无极网站制作等企业网站建设、网页设计与制作、无极企业网站模板建站服务,十年无极做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
Microsoft Visual Studio Ultimate 2012 旗舰版 有效注册密钥:
YKCW6-BPFPF-BT8C9-7DCTH-QXGWC
- Microsoft Visual Studio Premium 2012 高级版 有效注册密钥:
MH2FR-BC9R2-84433-47M63-KQVWC
- Microsoft Visual Studio Professional 2012 专业版 有效注册密钥:
4D974-9QX42-9Y43G-YJ7JG-JDYBP
我常用的方法是:客户端和服务器端对发公钥(新生成的),传输时双方用对方的公钥加密数据,收到后用自己的私钥解密。
先实例化该类
Dim wrapper As New ClassLibrary1.Simple3Des("你的密钥")
然后
Dim cipherText As String = wrapper.EncryptData("要加密的文本")
或
Dim cipherText As String = wrapper.DecryptData("要揭秘的文本")
1.安装到GAC的程序是需要强类型签名的
2.看起来你想要的是实现COM注册而不是安装到GAC。搜索下关注用.Net开发COM接口的内容吧,我没有注册过所以不好乱说。
使用加密方式存储即可实现别人无法查看内容,加密的方式有很多,适用你这里使用的是可逆的算法,推荐你使用DES加密
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Namespace ZU14
NotInheritable Public Class DES
Private iv As String = "1234的yzo"
Private key As String = "123在yzo"
'/ summary
'/ DES加密偏移量,必须是=8位长的字符串
'/ /summary
Public Property IV() As String
Get
Return iv
End Get
Set
iv = value
End Set
End Property
'/ summary
'/ DES加密的私钥,必须是8位长的字符串
'/ /summary
Public Property Key() As String
Get
Return key
End Get
Set
key = value
End Set
End Property
'/ summary
'/ 对字符串进行DES加密
'/ /summary
'/ param name="sourceString"待加密的字符串/param
'/ returns加密后的BASE64编码的字符串/returns
Public Function Encrypt(sourceString As String) As String
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim ms As New MemoryStream()
Try
Dim inData As Byte() = Encoding.Default.GetBytes(sourceString)
Try
Dim cs As New CryptoStream(ms, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(inData, 0, inData.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Return Convert.ToBase64String(ms.ToArray())
Catch
End Try
Finally
ms.Dispose()
End Try
End Function 'Encrypt
'/ summary
'/ 对DES加密后的字符串进行解密
'/ /summary
'/ param name="encryptedString"待解密的字符串/param
'/ returns解密后的字符串/returns
Public Function Decrypt(encryptedString As String) As String
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim ms As New MemoryStream()
Try
Dim inData As Byte() = Convert.FromBase64String(encryptedString)
Try
Dim cs As New CryptoStream(ms, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(inData, 0, inData.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Return Encoding.Default.GetString(ms.ToArray())
Catch
End Try
Finally
ms.Dispose()
End Try
End Function 'Decrypt
'/ summary
'/ 对文件内容进行DES加密
'/ /summary
'/ param name="sourceFile"待加密的文件绝对路径/param
'/ param name="destFile"加密后的文件保存的绝对路径/param
Overloads Public Sub EncryptFile(sourceFile As String, destFile As String)
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException("指定的文件路径不存在!", sourceFile)
End If
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim btFile As Byte() = File.ReadAllBytes(sourceFile)
Dim fs As New FileStream(destFile, FileMode.Create, FileAccess.Write)
Try
Try
Dim cs As New CryptoStream(fs, des.CreateEncryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(btFile, 0, btFile.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Catch
Finally
fs.Close()
End Try
Finally
fs.Dispose()
End Try
End Sub 'EncryptFile
'/ summary
'/ 对文件内容进行DES加密,加密后覆盖掉原来的文件
'/ /summary
'/ param name="sourceFile"待加密的文件的绝对路径/param
Overloads Public Sub EncryptFile(sourceFile As String)
EncryptFile(sourceFile, sourceFile)
End Sub 'EncryptFile
'/ summary
'/ 对文件内容进行DES解密
'/ /summary
'/ param name="sourceFile"待解密的文件绝对路径/param
'/ param name="destFile"解密后的文件保存的绝对路径/param
Overloads Public Sub DecryptFile(sourceFile As String, destFile As String)
If Not File.Exists(sourceFile) Then
Throw New FileNotFoundException("指定的文件路径不存在!", sourceFile)
End If
Dim btKey As Byte() = Encoding.Default.GetBytes(key)
Dim btIV As Byte() = Encoding.Default.GetBytes(iv)
Dim des As New DESCryptoServiceProvider()
Dim btFile As Byte() = File.ReadAllBytes(sourceFile)
Dim fs As New FileStream(destFile, FileMode.Create, FileAccess.Write)
Try
Try
Dim cs As New CryptoStream(fs, des.CreateDecryptor(btKey, btIV), CryptoStreamMode.Write)
Try
cs.Write(btFile, 0, btFile.Length)
cs.FlushFinalBlock()
Finally
cs.Dispose()
End Try
Catch
Finally
fs.Close()
End Try
Finally
fs.Dispose()
End Try
End Sub 'DecryptFile
'/ summary
'/ 对文件内容进行DES解密,加密后覆盖掉原来的文件
'/ /summary
'/ param name="sourceFile"待解密的文件的绝对路径/param
Overloads Public Sub DecryptFile(sourceFile As String)
DecryptFile(sourceFile, sourceFile)
End Sub 'DecryptFile
End Class 'DES
End Namespace 'ZU14
对文本文件加密
Dim des As New ZU14.DES()
des.IV = "abcd哈哈笑"
des.Key = "必须八位"
'加密
des.EncryptFile("d:\a.txt", "d:\b.txt")
'解密
des.DecryptFile("d:\b.txt")
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流