田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 3 48
     12
3456789
10111213141516
17181920212223
24252627282930
31


站点统计

最新评论



Autodesk.AutoCAD.Internal.Utils.TextScr() Extmin->Pextmin Extmax->Pextmax
未知 VB.net SHA512   [ 日期:2022-05-22 ]   [ 来自:本站原创 ]  HTML
Module file_crypt
    Dim input, output, password, codec As String
    Dim b() As Byte
    Dim c() As Byte
    Dim d, k As Integer
    Dim ren As Boolean
    Public Function StringSHA512(ByVal keys As String)
        Dim SHA512 As String = ""
        Dim c As String
        Dim key(100) As Byte
        For n = 0 To keys.Length - 1
            key(n) = Asc(keys.Chars(n))
        Next
        keys = Nothing
        key = System.Security.Cryptography.SHA512.Create().ComputeHash(key)
        For n = 0 To key.Length - 1
            c = Conversion.Hex(key(n))
            If c.Length = 1 Then
                c = "0" & c
            End If
            keys &= c
        Next
        keys = keys.ToLower
        Return keys
    End Function
    Sub Main()
0:      password = ""
        codec = ""
        Console.Title = "文件加密"
        Console.ForegroundColor = ConsoleColor.DarkGreen
        Console.WriteLine("文件加密")
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine("输入要编码/解码的文件的路径:")
1:      Console.Write("> ")
        input = Console.ReadLine
        input = input.Replace("/", "\")
        input = input.Replace("""", "")
        If My.Computer.FileSystem.FileExists(input) = False Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("您输入的路径无效!")
            Console.ForegroundColor = ConsoleColor.White
            GoTo 1
        End If
        Dim bytes() As Byte = My.Computer.FileSystem.ReadAllBytes(input)
        Console.WriteLine("输入保存文件的路径:")
2:      Console.Write("> ")
        output = Console.ReadLine
        output = output.Replace("/", "\")
        output = output.Replace("""", "")
        If My.Computer.FileSystem.DirectoryExists(Left(output, output.Length - output.Split("\")(output.Split("\").Length - 1).Length)) = False Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("您输入的路径无效!")
            Console.ForegroundColor = ConsoleColor.White
            GoTo 2
        End If
        If ren = True Then GoTo 3
3:      If My.Computer.FileSystem.FileExists(output) = True Then
            Console.WriteLine("在为输出文件选择的位置中,有另一个文件。")
            Console.WriteLine("键入""继续执行(0)""或""重新输入(1)""。")
4:          Dim answer As String = Console.ReadLine.ToLower
            If answer = "1" Then
                ren = True
                Console.WriteLine("输入保存文件的路径:")
                GoTo 2
            ElseIf answer = "0" Then
                Console.WriteLine("继续进行:")
            ElseIf Not answer = "0" Then
                Console.ForegroundColor = ConsoleColor.Red
                Console.WriteLine("无法识别该命令!")
                Console.ForegroundColor = ConsoleColor.White
                GoTo 4
            End If
        End If
        Console.WriteLine("请输入密码:")
5:      Console.Write("> ")
        password = Console.ReadLine
        If password = "" Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("您尚未输入任何密码!请输入后重试。")
            Console.ForegroundColor = ConsoleColor.White
            GoTo 5
        End If
        password = StringSHA512(password)
        Console.WriteLine("选择文件是应加密(0)还是解密(1):")
6:      Console.Write("> ")
        codec = Console.ReadLine
        If Not codec = "0" And Not codec = "1" Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("尚未输入"“0”" 或 "“1”",然后重试。")
            Console.ForegroundColor = ConsoleColor.White
            GoTo 6
        End If
        k = 0
        Console.ForegroundColor = ConsoleColor.Blue
        If codec = "1" Then
            Console.WriteLine("文件解密开始了!")
            ReDim c(0)
            For n = 0 To bytes.Length - 1
                If password.Length - 1 < k Then k = 0
                d = bytes(n) + Asc(password.Chars(k))
                If d > 255 Then c(0) = d - 256 Else c(0) = d
                My.Computer.FileSystem.WriteAllBytes(output, c, True)
                k += 1
                Console.Title = "加密文件 正在进行中..." & (100 * n / (bytes.Length - 1)).ToString("0.000") & "%"
            Next
        Else
            Console.WriteLine("文件加密开始!")
            ReDim c(0)
            For n = 0 To bytes.Length - 1
                If password.Length - 1 < k Then k = 0
                d = bytes(n) - Asc(password.Chars(k))
                If d < 0 Then c(0) = 256 + d Else c(0) = d
                My.Computer.FileSystem.WriteAllBytes(output, c, True)
                k += 1
                Console.Title = "加密文件 正在进行中... " & (100 * n / (bytes.Length - 1)).ToString("0.000") & "%"
            Next
        End If
        bytes = Nothing
        Console.ForegroundColor = ConsoleColor.Green
        If codec = "1" Then Console.Write("解密") Else Console.Write("加密")
        Console.WriteLine(" 执行成功!")
        Console.ForegroundColor = ConsoleColor.White
        Console.WriteLine("键入""0""以退出,键入""1""以继续。")
7:      Console.Write("> ")
        Dim cmd As String = Console.ReadLine.ToLower
        If cmd = "1" Then
            GoTo 0
        ElseIf Not cmd = "0" Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("无法识别该命令!")
            Console.ForegroundColor = ConsoleColor.White
            GoTo 7
        End If
    End Sub
End Module



暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:1*6=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©