Transforms (that is, encrypts or decrypts) raw data using an RSA public key.
Public Declare Function RSA_RawPublic Lib "diCrPKI.dll"
(ByRef lpData As Byte, ByVal nDataLen As Long,
ByVal strPublicKey As String, ByVal nOptions As Long) As Long
nRet = RSA_RawPublic(lpData(0), nDataLen, strPublicKey, nOptions)
long __stdcall RSA_RawPublic(unsigned char *lpData, long nDataLen, const char *szPublicKey, long nOptions);
If successful, the return value is zero; otherwise it returns a nonzero error code.
Public Function rsaRawPublic (lpData() As Byte, szPublicKey As String, Optional nOptions As Long = 0) As Byte()
Rsa.RawPublic Method (Byte[], String)
Rsa.RawPublic Method (Byte[], String, Int32)
static bvec_t dipki::Rsa::RawPublic (const bvec_t &data, const std::string &keyStr)
static Rsa.raw_public(block, pubkeystr)
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 = "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
Dim strPrivateKey As String
Dim pt() As Byte
Dim ct() As Byte
strPrivateKey = rsaReadPrivateKey("rsa508.p8e", "password")
Debug.Assert Len(strPrivateKey) > 0
pt = cnvBytesFromHexStr("0001ffffffffffffffffffffffffffff" & _
"ffffffffffffffffffffffffff003020" & _
"300c06082a864886f70d020205000410" & _
"dca9ecf1c15c1bd266aff9c8799365cd")
ct = rsaRawPrivate(pt, strPrivateKey)
Debug.Print "CT=" & cnvHexStrFromBytes(ct)
Dim strPublicKey As String
Dim dt() As Byte
strPublicKey = rsaReadPublicKey("Rsa508.pub")
Debug.Assert Len(strPublicKey) > 0
dt = rsaRawPublic(ct, strPublicKey)
Debug.Print "DT=" & cnvHexStrFromBytes(dt)
RSA_RawPrivate RSA_EncodeMsg Raw RSA Techniques