Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Encryption.vb
Package: SALEOUTSYSTEM.rar [view]
Upload User: wj57717022
Upload Date: 2014-12-16
Package Size: 4093k
Code Size: 3k
Category:
hospital software system
Development Platform:
Visual Basic
- Imports System.Security
- Imports System.Security.Cryptography
- Imports System.Text
- Imports Microsoft.Win32
- 'sKey输入密码的时候,必须使用英文字符,区分大小写,且字符数量是8个,不能多也不能少,否则出错
- Public Class Encryption
- Public Shared Function Encrypt(ByVal pToEncrypt As String, ByVal sKey As String) As String
- Dim des As New DESCryptoServiceProvider
- Dim inputByteArray() As Byte
- inputByteArray = Encoding.Default.GetBytes(pToEncrypt)
- ''建立加密对象的密钥和偏移量
- ''原文使用ASCIIEncoding.ASCII方法的GetBytes方法
- ''使得输入密码必须输入英文文本
- des.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
- des.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
- ''写二进制数组到加密流
- ''(把内存流中的内容全部写入)
- Dim ms As New System.IO.MemoryStream
- Dim cs As New CryptoStream(ms, des.CreateEncryptor, CryptoStreamMode.Write)
- ''写二进制数组到加密流
- ''(把内存流中的内容全部写入)
- cs.Write(inputByteArray, 0, inputByteArray.Length)
- cs.FlushFinalBlock()
- ''建立输出字符串
- Dim ret As New StringBuilder
- Dim b As Byte
- For Each b In ms.ToArray()
- ret.AppendFormat("{0:X2}", b)
- Next
- Return ret.ToString()
- End Function
- ''解密方法
- Public Shared Function Decrypt(ByVal pToDecrypt As String, ByVal sKey As String) As String
- Dim des As New DESCryptoServiceProvider
- ''把字符串放入byte数组
- Dim len As Integer
- len = pToDecrypt.Length / 2 - 1
- Dim inputByteArray(len) As Byte
- Dim x, i As Integer
- For x = 0 To len
- i = Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16)
- inputByteArray(x) = CType(i, Byte)
- Next
- ''建立加密对象的密钥和偏移量,此值重要,不能修改
- des.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
- des.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
- Dim ms As New System.IO.MemoryStream
- Dim cs As New CryptoStream(ms, des.CreateDecryptor, CryptoStreamMode.Write)
- cs.Write(inputByteArray, 0, inputByteArray.Length)
- cs.FlushFinalBlock()
- Return Encoding.Default.GetString(ms.ToArray)
- End Function
- Public Shared Function readregedit() As Boolean
- Dim State As RegistryKey
- State = Registry.LocalMachine.OpenSubKey("SOFTWAREJxcDFT StudioRegister")
- Try
- Dim StateValue As String
- '注意:注册表值取分大小写
- StateValue = State.GetValue("State")
- If StateValue = "Yes" Then
- Return True
- End If
- Catch
- End Try
- End Function
- Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
- (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Integer, ByRef lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Integer, ByVal lpFileSystemFlags As Integer, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Integer) As Integer
- End Class