Function SM4_string(ByVal data As String, ByVal Key As String) As String
Dim dataarray(15) As Byte
Dim keyarray(15) As Byte
Dim output(15) As Byte
Dim i As Integer
dataarray = BCD2bytearray(data)
'For i = 0 To 15
keyarray = BCD2bytearray(Key)
Call SM4_DECRY(dataarray(0), keyarray(0), output(0))
SM4_string = bytearray2string(output)
End Function
'整數byte陣列轉十六進制string
Function bytearray2string(ByRef bytearray() As Byte) As String
Dim hexstring As String
Dim i As Integer
Dim temp As String
bytearray2string = ""
For i = 0 To 15
temp = fun_DEC_to_HEX(bytearray(i))
bytearray2string = bytearray2string & temp
i = i + 1
Next i
End Function
'String型別的BCD碼(32個16進制字符轉成16位的十進制byte陣列)
Public Function BCD2bytearray(ByVal BCD As String)
Dim bcdint(15) As Byte
Dim i As Integer
Dim temp As String
Dim j As Integer
j = 0
For i = 1 To 31 Step 2
temp = Mid(BCD, i, 2)
bcdint(j) = fun_BCD_to_DEC(temp)
j = j + 1
Next i
BCD2bytearray = bcdint
End Function
BCD2bytearray函式是把string型別拆分成十進制的byte陣列,然后在sm4_string中被呼叫,但是在dataarray = BCD2bytearray(data)中報錯,can't assign to array。本人菜鳥,求大神解決方法。
uj5u.com熱心網友回復:
Function SM4_string(ByVal data As String, ByVal Key As String) As String
Dim dataarray(15) As Byte
Dim keyarray(15) As Byte
Dim output(15) As Byte
Dim i As Integer
dataarray = BCD2bytearray(data)
'For i = 0 To 15
keyarray = BCD2bytearray(Key)
Call SM4_DECRY(dataarray(0), keyarray(0), output(0))
SM4_string = bytearray2string(output)
End Function
'整數byte陣列轉十六進制string
Function bytearray2string(ByRef bytearray() As Byte) As String
Dim hexstring As String
Dim i As Integer
Dim temp As String
bytearray2string = ""
For i = 0 To 15
temp = fun_DEC_to_HEX(bytearray(i))
bytearray2string = bytearray2string & temp
i = i + 1
Next i
End Function
'String型別的BCD碼(32個16進制字符轉成16位的十進制byte陣列)
Public Function BCD2bytearray(ByVal BCD As String) As Byte()
Dim bcdint(15) As Byte
Dim i As Integer
Dim temp As String
Dim j As Integer
j = 0
For i = 1 To 31 Step 2
temp = Mid(BCD, i, 2)
bcdint(j) = fun_BCD_to_DEC(temp)
j = j + 1
Next i
BCD2bytearray = bcdint
End Function
少了個as byte()宣告,但是還是不行。求指教啊啊啊 啊急死了!
uj5u.com熱心網友回復:
被賦值的資料不能是靜態陣列,要改為動態的Dim dataarray() As Byte
Dim keyarray() As Byte
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/110941.html
標籤:VB基礎類
上一篇:現在想一個 出入庫管理系統
