RSA_RawPublic transforms (i.e. encrypts or decrypts) raw data using an RSA public key.
Public Declare Function RSA_RawPublic Lib "diCrPKI.dll"
(ByRef abData As Byte, ByVal nDataLen As Long,
ByVal strPublicKey As String, ByVal nOptions As Long) As Long
nRet = RSA_RawPublic(abData(0), nDataLen, strPublicKey, nOptions)
Byte array containing the data to be transformed.Long specifying the number of bytes of data.String containing the RSA public key string.Long option flags. Set to zero.
long _stdcall RSA_RawPublic(unsigned char *abData, long nDataLen,
const char *szPublicKey64, long nOptions);
Long: If successful, the return value is zero;
otherwise it returns a non-zero error code.
Rsa.RawPublic Method (Byte[], String)
Rsa.RawPublic Method (Byte[], String, Int32)
The data must be the same length as the RSA key modulus (use RSA_KeyBytes to find out this).
The output is written over the input. The RSA public key must be provided in the internal key string format.
This is from Example 4.2 of [SMIME-EX]:
Dim sEncDataHex As String
Dim abData() As Byte
Dim nDataLen As Long
Dim strCertFile As String
Dim nKeyLen As Long
Dim strPublicKey As String
Dim nRet As Long
' Cut and paste from DUMPASN1 output
sEncDataHex = "2F 23 82 D2 F3 09 5F B8 0C 58 EB 4E" & _
"9D BF 89 9A 81 E5 75 C4 91 3D D3 D0" & _
"D5 7B B6 D5 FE 94 A1 8A AC E3 C4 84" & _
"F5 CD 60 4E 27 95 F6 CF 00 86 76 75" & _
"3F 2B F0 E7 D4 02 67 A7 F5 C7 8D 16" & _
"04 A5 B3 B5 E7 D9 32 F0 24 EF E7 20" & _
"44 D5 9F 07 C5 53 24 FA CE 01 1D 0F" & _
"17 13 A7 2A 95 9D 2B E4 03 95 14 0B" & _
"E9 39 0D BA CE 6E 9C 9E 0C E8 98 E6" & _
"55 13 D4 68 6F D0 07 D7 A2 B1 62 4C" & _
"E3 8F AF FD E0 D5 5D C7"
' Convert to bytes
abData = cnvBytesFromHexStr(sEncDataHex)
' Check
Debug.Print cnvHexStrFromBytes(abData)
strCertFile = "C:\Test\AliceRSASignByCarl.cer"
' Read in PublicKey as base64 string - pre-dimension first
nKeyLen = RSA_GetPublicKeyFromCert("", 0, strCertFile, 0)
Debug.Print "KeyLen = " & nKeyLen
If nKeyLen <= 0 Then
Debug.Print pkiGetLastError()
MsgBox "Unable to retrieve private key"
Exit Function
End If
' Pre-dimension the string to receive data
strPublicKey = String(nKeyLen, " ")
' Read in the Key
nRet = RSA_GetPublicKeyFromCert(strPublicKey, nKeyLen, strCertFile, 0)
Debug.Print "PubKey= " & strPublicKey
' Verify using the public key
nDataLen = UBound(abData) + 1
Debug.Print "Input: " & cnvHexStrFromBytes(abData)
nRet = RSA_RawPublic(abData(0), nDataLen, strPublicKey, 0)
Debug.Print "Output: " & cnvHexStrFromBytes(abData)
Stripping the PKCS-1.5 header 0001FFFF...FF00 from the output, we should get
3021300906052B0E03021A05000414406AEC085279BA6E16022D9E0629C0229687DD48
which is a DigestInfo containing the 20-byte SHA-1 hash
406AEC085279BA6E16022D9E0629C0229687DD48
RSA_RawPrivate RSA_EncodeMsg Raw RSA Techniques