Decodes an EME or EMSA encoded message block according to PKCS#1.
VB6/VBA
Debug.Print "Testing RSA_DecodeMsg ..." Dim abData() As Byte Dim abBlock() As Byte Dim abDigest() As Byte Dim abDigInfo() As Byte Dim nDataLen As Long Dim nBlockLen As Long Dim nLen As Long Dim nRet As Long Dim nOptions As Long ' 0. Create an encoded test block ready for for signing abData = StrConv("abc", vbFromUnicode) nDataLen = UBound(abData) - LBound(abData) + 1 nBlockLen = 64 ReDim abBlock(nBlockLen - 1) nRet = RSA_EncodeMsg(abBlock(0), nBlockLen, abData(0), nDataLen, PKI_EMSIG_PKCSV1_5) Debug.Print "BLOCK =" & cnvHexStrFromBytes(abBlock) ' 1. Extract the message digest =SHA1("abc") nLen = RSA_DecodeMsg(0, 0, abBlock(0), nBlockLen, PKI_EMSIG_PKCSV1_5) If nLen < 0 Then MsgBox "Decryption Error": Exit Sub Debug.Print "Message digest is " & nLen & " bytes long" ReDim abDigest(nLen - 1) nLen = RSA_DecodeMsg(abDigest(0), nLen, abBlock(0), nBlockLen, PKI_EMSIG_PKCSV1_5) Debug.Print "HASH =" & cnvHexStrFromBytes(abDigest) ' 2. Extract the full DigestInfo data nOptions = PKI_EMSIG_PKCSV1_5 + PKI_EMSIG_DIGINFO nLen = RSA_DecodeMsg(0, 0, abBlock(0), nBlockLen, nOptions) If nLen < 0 Then MsgBox "Decryption Error": Exit Sub Debug.Print "DigestInfo is " & nLen & " bytes long" ReDim abDigest(nLen - 1) nLen = RSA_DecodeMsg(abDigest(0), nLen, abBlock(0), nBlockLen, nOptions) Debug.Print "DIGINFO=" & cnvHexStrFromBytes(abDigest)
Output
Testing RSA_DecodeMsg ... BLOCK =0001FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF003021300906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D Message digest is 20 bytes long HASH =A9993E364706816ABA3E25717850C26C9CD0D89D DigestInfo is 35 bytes long DIGINFO=3021300906052B0E03021A05000414A9993E364706816ABA3E25717850C26C9CD0D89D
VB.NET
Console.WriteLine("Testing RSA_DecodeMsg ...")
Dim abData() As Byte
Dim abBlock() As Byte
Dim abDigest() As Byte
Dim abDigInfo() As Byte
Dim nDataLen As Integer
Dim nBlockLen As Integer
' 0. Create an encoded test block ready for for signing
abData = System.Text.Encoding.Default.GetBytes("abc")
nDataLen = UBound(abData) - LBound(abData) + 1
nBlockLen = 64
abBlock = Rsa.EncodeMsgForSignature(nBlockLen, abData, HashAlgorithm.Sha1)
Console.WriteLine("BLOCK =" & Cnv.ToHex(abBlock))
' 1. Extract the message digest =SHA1("abc")
abDigest = Rsa.DecodeDigestForSignature(abBlock)
If abDigest.Length = 0 Then
Console.WriteLine("Decryption Error")
Exit Sub
End If
Console.WriteLine("Message digest is " & abDigest.Length & " bytes long")
Console.WriteLine("HASH =" & Cnv.ToHex(abDigest))
' 2. Extract the full DigestInfo data
abDigInfo = Rsa.DecodeDigestForSignature(abBlock, True)
If abDigInfo.Length = 0 Then
Console.WriteLine("Decryption Error")
Exit Sub
End If
Console.WriteLine("DigestInfo is " & abDigInfo.Length & " bytes long")
Console.WriteLine("DIGINFO=" & Cnv.ToHex(abDigInfo))
[Contents]