最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
加密与解密
时间:2022-07-02 12:14:48 编辑:袖梨 来源:一聚教程网
Imports System.IO
Imports System.Security.Cryptography
'数据加/解密 类
Public Class CryData
'加密密钥,初始化向量
Public ReadOnly cryKey As Byte() = {9, 4, 2, 8, 5, 1, 4, 9, 7, 6, 9, 5, 1, 13, 7, 5, 14, 9, 10, 15, 0, 1, 14, 5, 9, 4, 3, 8, 2, 10}
Public ReadOnly cryIV As Byte() = {7, 1, 8, 8, 2, 8, 7, 1, 4, 5, 6, 3, 5, 6, 7}
' 文件加密
Public Sub EncryptData(ByVal inName As String, ByVal outName As String, _
Optional ByVal rijnKey() As Byte = Nothing, _
Optional ByVal rijnIV() As Byte = Nothing)
If rijnKey Is Nothing Then
rijnKey = cryKey
End If
If rijnIV Is Nothing Then
rijnIV = cryIV
End If
ReDim Preserve rijnKey(31)
ReDim Preserve rijnIV(15)
'Create the file streams to handle the input and output files.
Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
Dim fout As New FileStream(outName, FileMode.OpenOrCreate, FileAccess.ReadWrite)
fout.SetLength(0)
'Create variables to help with read and write.
Dim bin(1024) As Byte 'This is intermediate storage for the encryption.
Dim rdlen As Long = 0 'This is the total number of bytes written.
Dim totlen As Long = fin.Length 'Total length of the input file.
Dim len As Integer 'This is the number of bytes to be written at a time.
'Creates the default implementation, which is RijndaelManaged.
Imports System.Security.Cryptography
'数据加/解密 类
Public Class CryData
'加密密钥,初始化向量
Public ReadOnly cryKey As Byte() = {9, 4, 2, 8, 5, 1, 4, 9, 7, 6, 9, 5, 1, 13, 7, 5, 14, 9, 10, 15, 0, 1, 14, 5, 9, 4, 3, 8, 2, 10}
Public ReadOnly cryIV As Byte() = {7, 1, 8, 8, 2, 8, 7, 1, 4, 5, 6, 3, 5, 6, 7}
' 文件加密
Public Sub EncryptData(ByVal inName As String, ByVal outName As String, _
Optional ByVal rijnKey() As Byte = Nothing, _
Optional ByVal rijnIV() As Byte = Nothing)
If rijnKey Is Nothing Then
rijnKey = cryKey
End If
If rijnIV Is Nothing Then
rijnIV = cryIV
End If
ReDim Preserve rijnKey(31)
ReDim Preserve rijnIV(15)
'Create the file streams to handle the input and output files.
Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
Dim fout As New FileStream(outName, FileMode.OpenOrCreate, FileAccess.ReadWrite)
fout.SetLength(0)
'Create variables to help with read and write.
Dim bin(1024) As Byte 'This is intermediate storage for the encryption.
Dim rdlen As Long = 0 'This is the total number of bytes written.
Dim totlen As Long = fin.Length 'Total length of the input file.
Dim len As Integer 'This is the number of bytes to be written at a time.
'Creates the default implementation, which is RijndaelManaged.
相关文章
- 云星穹铁道权益升级怎么玩 云崩铁权益升级活动介绍 12-03
- 以闪亮之名山中绘梦怎么玩 以闪亮之名滢然花梦套装活动介绍 12-03
- 以闪亮之名绿野梦歌礼包怎么样 以闪亮之名绿野梦歌拍照礼包介绍 12-03
- 光遇12.6有什么更新 光遇12月6日更新内容介绍 12-03
- 伍六七暗影交锋测试资格怎么获得 伍六七暗影交锋内测资格获取方法 12-03
- 无限暖暖晶莹诗集怎么样 12-03