[VB6 equivalent: RSA_KeyMatch
]
Dim strCertFile As String Dim strKeyFile As String Dim sbPassword As StringBuilder Dim sbPublicKey As StringBuilder Dim sbPrivateKey As StringBuilder Dim nRet As Integer ' Input files strCertFile = "AAA010101AAAsd.cer" strKeyFile = "AAA010101AAA_0408021316S.key" ' Test password - CAUTION: DO NOT hardcode production passwords! sbPassword = New StringBuilder("Empresa1") ' Read in private key from encrypted .key file sbPrivateKey = Rsa.ReadPrivateKey(strKeyFile, sbPassword.ToString()) If sbPrivateKey.Length > 0 Then Console.WriteLine("Private key is " & Rsa.KeyBits(sbPrivateKey.ToString()) & " bits") Else Console.WriteLine("ERROR: Cannot read private key file.") Exit Sub End If ' Clean up password as we are done with it Wipe.String(sbPassword) ' Read in public key from certificate sbPublicKey = Rsa.ReadPublicKey(strCertFile) If sbPublicKey.Length > 0 Then Console.WriteLine("Public key is " & Rsa.KeyBits(sbPublicKey.ToString()) & " bits") Else Console.WriteLine("ERROR: Cannot read certificate file.") Exit Sub End If ' See if the two key strings match nRet = Rsa.KeyMatch(sbPrivateKey.ToString(), sbPublicKey.ToString()) If nRet = 0 Then Console.WriteLine("OK, key strings match.") Else Console.WriteLine("FAILED: key strings do not match.") End If ' Clean up private key string Wipe.String(sbPrivateKey)
See Also:
Rsa.KeyMatch Method (StringBuilder)
Rsa.KeyMatch Method (String)