【开源项目】花密(Flower Password)VB版之HMAC-MD5算法

该博客介绍了一个VB版本的HMAC-MD5算法实现,通过UnicodeToUtf8转换字符串为字节,然后进行密钥和密码的预处理,结合MD5更新和最终化过程,生成HMAC-MD5散列值。
Public Function Hmac_MD5(ByVal in_password As String, ByVal in_key As String) As String

    Dim bytpassword() As Byte

    bytpassword = UnicodeToUtf8(in_password)

    Dim in_password_len As Long

    in_password_len = UBound(bytpassword) - LBound(bytpassword) + 1

    Dim bytkey() As Byte

    bytkey = UnicodeToUtf8(in_key)

    Dim in_key_len As Long

    in_key_len = UBound(bytkey) - LBound(bytkey) + 1

    If in_key_len > 64 Then
        MD5Init
        MD5Update in_key_len, bytkey
        MD5Final
        ReDim bytkey(0 To 15)
        bytkey = Hash2Byte(GetValues)
        in_key_len = 16

    End If

    Dim ipad(0 To 63) As Byte

    Dim i             As Integer

    For i = LBound(ipad) To UBound(ipad)

        If i > UBound(bytkey) Then
            ipad(i) = &H36
        Else
            ipad(i) = bytkey(i) Xor &H36

        End If

    Next
    MD5Init
    MD5Update 64, ipad
    MD5Update in_password_len, bytpassword
    MD5Final
CNBJX-原创函数,首发CSND 3.1 Base64 ------------------------------------------------------------------------------- Base64Decode(Str) Base64DecodeRaw(Str) as byte() Base64Encode(Str) FileBase64(file) 3.2 Hex ------------------------------------------------------------------------------- HexDecode(Str) HexDecodeRaw(Str) as byte() HexEncode(Str) File2Hex(file) 3.3 hash String ------------------------------------------------------------------------------- stringOrByte : 可以是字条串或字节数组 ChatSet : 可选,指定编码 MD2(stringOrByte, [ChatSet As String]) As String MD4(stringOrByte, [ChatSet As String]) As String MD5(stringOrByte, [ChatSet As String]) As String SHA1(stringOrByte, [ChatSet As String]) SHA256(stringOrByte, [ChatSet As String]) As String SHA384(stringOrByte, [ChatSet As String]) As String SHA512(stringOrByte, [ChatSet As String]) As String 3.4 hash Byte ------------------------------------------------------------------------------- abytData : 字节数组 asp里请加()号 如: bytes="" md5_byte((bytes),0,0) 可选参数 iStart iEnd 默认为0,取整个 bytes的hash值 ---------------------------------------------------- [可选] iStart: 起始位置 [可选] iEnd:结束位置 分块取值有几种情况 1: iStart = 0 , iEnd = 1024 * 1024 * 1 '读取前面1M 2: iStart = -1024 * 1024 * 1 , iEnd = 0 '读取后面1M 3: iStart = 10, iEnd = iStart + 10 '读取第10个字节后的10个字节 (10-20) 4: iStart = -20,iEnd = -10 '读取尾部 (-20 -> -10 的字节) ---------------------------------------------------- MD2_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String MD4_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String MD5_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA1_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA256_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA384_Byte(abytData As Array(Byte), [iStart As Double = 0], [iEnd As Double = 0]) As String SHA
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值