VBA调用.NET下System.Security.Cryptography命名空间实现常用的加密解密算法

该博客介绍了如何使用VBA调用.NET的System.Security.Cryptography命名空间,实现包括MD5, SHA1, SHA256, SHA384, SHA512, HMAC-MD5, HMAC-SHA1, HMAC-SHA256, HMAC-SHA384, HMAC-SHA512等摘要算法,以及DES, 3DES, AES的对称加解密法。此外,还详细讲解了RSA非对称加解密,包括公钥加密私钥解密和私钥签名公钥验证的案例。" 126788377,14557663,Unity新输入系统InputSystem详解,"['Unity3D', 'C#', '游戏引擎', '输入管理']
摘要由CSDN通过智能技术生成

1.摘要算法

1.1 MD系列

1.1.1 MD5

Public Function MD5(body() As Byte) As Byte()
    Dim oMD5 As Object
    Set oMD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")
    MD5 = oMD5.ComputeHash_2(body)
End Function

1.2 SHA系列

1.2.1 SHA1

Public Function SHA1(body() As Byte) As Byte()
    Dim oSHA1 As Object
    Set oSHA1 = CreateObject("System.Security.Cryptography.SHA1Managed")
    SHA1 = oSHA1.ComputeHash_2(body)
End Function

1.2.2 SHA256

Public Function SHA256(body() As Byte) As Byte()
    Dim oSHA256 As Object
    Set oSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")
    SHA256 = oSHA256.ComputeHash_2(body)
End Function

1.2.3 SHA384

Public Function SHA384(body() As Byte) As Byte()
    Dim oSHA384 As Object
    Set oSHA384 = CreateObject("System.Security.Cryptography.SHA384Managed")
    SHA384 = oSHA384.ComputeHash_2(body)
End Function

1.2.4 SHA512

Public Function SHA512(body() As Byte) As Byte()
    Dim oSHA512 As Object
    Set oSHA512 = CreateObject("System.Security.Cryptography.SHA512Managed")
    SHA512 = oSHA512.ComputeHash_2(body)
End Function

1.3 HMAC系列

1.3.1 HMAC-MD5

Public Function HmacMD5(body() As Byte, key() As Byte) As Byte()
    Dim oHmacMD5 As Object
    Set oHmacMD5 = CreateObject("System.Security.Cryptography.HMACMD5")
    oHmacMD5.key = key
    HmacMD5 = oHmacMD5.ComputeHash_2(body)
End Function

1.3.2 HMAC-SHA1

Public Function HmacSHA1(body() As Byte, key() As Byte) As Byte()
    Dim oHmacSHA1 As Object
    Set oHmacSHA1 = CreateObject("System.Security.Cryptography.HMACSHA1")
    oHmacSHA1.key = key
    HmacSHA1 = oHmacSHA1.ComputeHash_2(body)
End Function

1.3.3 HMAC-SHA256

Public 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值