Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共2 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:字符串加密问题

1楼
191422411 发表于:2024/12/11 18:00:00
老师们好,在vb.net中如何写出和加密过程,使其加密的字符串和foxtable加密的字符串一致
以下运行正常,但加密后的结果和foxtable的不一样,自无法解密还原,该如何修改哪里。我想用其做一个生成配置信息的小程序


Module Program
    Sub Main()
        ' 您提供的密钥和IV
        Dim Key As String = "a23"  ' 密钥长度需要是16、24或32字节
        Dim IV As String = "op#"   ' IV长度必须是16字节

        ' 确保Key和IV的长度正确
        Dim keyBytes As Byte() = New Byte(15) {}
        Dim ivBytes As Byte() = New Byte(15) {}

        ' 填充Key和IV数组
        'Array.Copy(Encoding.UTF8.GetBytes(Key.PadRight(16, " ")), 0, keyBytes, 0, Math.Min(Key.Length, 16))
        'Array.Copy(Encoding.UTF8.GetBytes(IV.PadRight(16, " ")), 0, ivBytes, 0, Math.Min(IV.Length, 16))

        Dim Val1 As String = "龙的传人"
        Dim Val2 As String = EncryptText(Val1, keyBytes, ivBytes) '加密
        Dim Val3 As String = DecryptText(Val2, keyBytes, ivBytes) '解密,两个密钥必须和加密的时候相同 
        Console.WriteLine("加密后:" & Val2)
        Console.WriteLine("解密后:" & Val3)
    End Sub

    '加密函数
    Function EncryptText(ByVal plainText As String, ByVal Key() As Byte, ByVal IV() As Byte) As String
        Dim encryptProvider As New AesCryptoServiceProvider()
        encryptProvider.Key = Key
        encryptProvider.IV = IV
        Dim inputBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
        Using encryptor As ICryptoTransform = encryptProvider.CreateEncryptor()
            Dim encryptedBytes() As Byte = encryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length)
            Return Convert.ToBase64String(encryptedBytes)
        End Using
    End Function

    '解密函数
    Function DecryptText(ByVal cipherText As String, ByVal Key() As Byte, ByVal IV() As Byte) As String
        Dim decryptProvider As New AesCryptoServiceProvider()
        decryptProvider.Key = Key
        decryptProvider.IV = IV
        Dim inputBytes As Byte() = Convert.FromBase64String(cipherText)
        Using decryptor As ICryptoTransform = decryptProvider.CreateDecryptor()
            Dim decryptedBytes() As Byte = decryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length)
            Return Encoding.UTF8.GetString(decryptedBytes)
        End Using
    End Function
End Module
2楼
有点蓝 发表于:2024/12/12 8:40:00
foxtable自带的加解密功能无法和第三方的加解密功能兼容。如果使用第三方的,就全部使用第三方的就好
共2 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02246 s, 2 queries.