CryptoSys PKI Pro Manual

RSA_KeyValue

Extracts a base64-encoded RSA key value from internal key string.

VBA/VB6 Syntax

Public Declare Function RSA_KeyValue Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyString As String, ByVal strFieldName As String, ByVal nOptions As Long) As Long

nRet = RSA_KeyValue(strOutput, nOutChars, strKeyString, strFieldName, nOptions)

C/C++ Syntax

long __stdcall RSA_KeyValue(char *szOutput, long nOutChars, const char *szKeyString, const char *szFieldName, long nOptions);

Parameters

szOutput
[out] string of sufficient length to receive the output
nOutChars
[in] specifying the maximum number of characters to be received
szKeyString
[in] Public or private key in internal string format
szFieldName
[in] Name of field to be extracted: "Modulus" or "Exponent"
nOptions
[in] option flags. Set to zero.

Returns (VBA/C)

If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function rsaKeyValue (szKeyString As String, szFieldName As String, Optional nOptions As Long = 0) As String

.NET Equivalent

Rsa.KeyValue Method

C++ (STL) Equivalent

static std::string dipki::Rsa::KeyValue (const std::string &keyStr, const std::string &fieldName)

Python Equivalent

static Rsa.key_value(keystr, fieldname)

Remarks

For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.

The output is a continuous string of base64 characters suitable for a <RSAKeyValue> node in an XML-DSIG document.

A typical <RSAKeyValue> node looks like this:

<RSAKeyValue>
  <Modulus>
    4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8
    ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=
  </Modulus>
  <Exponent>AQAB</Exponent>
</RSAKeyValue>

Use this function to populate the fields <Modulus> and <Exponent> for a given RSA key, or to use the values in other computations.

Example (VBA core function)

Dim nChars As Long
Dim strKeyString As String
Dim strFieldName As String
Dim strValue As String

' Read in key to internal string
strKeyString = rsaReadPublicKey("AliceRSASignByCarl.cer")

strFieldName = "Modulus"
nChars = RSA_KeyValue("", 0, strKeyString, strFieldName, 0)
If (nChars < 0) Then
    Debug.Print "ERROR: " & pkiErrorLookup(nChars)
    Exit Sub
End If
' Dimension output
strValue = String(nChars, " ")
nChars = RSA_KeyValue(strValue, nChars, strKeyString, strFieldName, 0)
Debug.Print strFieldName & "=" & strValue

strFieldName = "Exponent"
nChars = RSA_KeyValue("", 0, strKeyString, strFieldName, 0)
If (nChars < 0) Then
    Debug.Print "ERROR: " & pkiErrorLookup(nChars)
    Exit Sub
End If
' Dimension output
strValue = String(nChars, " ")
nChars = RSA_KeyValue(strValue, nChars, strKeyString, strFieldName, 0)
Debug.Print strFieldName & "=" & strValue
Modulus=4IlzOY3Y9fXoh3Y5f06wBbt ... +Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=
Exponent=AQAB

Example (VBA wrapper function)

Dim strKeyString As String
Dim strFieldName As String
Dim strValue As String

strKeyString = rsaReadPublicKey("AliceRSASignByCarl.cer")
strFieldName = "Modulus"
strValue = rsaKeyValue(strKeyString, strFieldName)
Debug.Print strFieldName & "=" & strValue
strFieldName = "Exponent"
strValue = rsaKeyValue(strKeyString, strFieldName)
Debug.Print strFieldName & "=" & strValue

See Also

[Contents] [Index]

[PREV: RSA_KeyMatch...]   [Contents]   [Index]   
   [NEXT: RSA_MakeKeys...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.