Discuss this help topic in SecureBlackbox Forum
Verify asymmetric signature
With asymmetric, or public key, cryptography, the sender can sign data using his secret key. Upon receipt of the signed data the recipient can verify signature's authenticity with the corresponding public key. Often a public key of an entity is contained in its public X.509 certificates. The private key is typically contained in a separate file, or even on a hardware device.
Typical low-level signature is essentially a cryptographic value that does not contain any identifier of the signing key. Therefore some identifier has to be conveyed with the signature, unless the key is known by the verifying party beforehand. To verify a digital signature with SecureBlackbox:
TElRSAKeyMaterial km = (TElRSAKeyMaterial)cert.KeyMaterial;
Note the explicit cast to TElRSAKeyMaterial type, the certificate's KeyMaterial property returns an instance of the parent TElPublicKeyMaterial class.
TElRSAPublicKeyCrypto crypto = new TElRSAPublicKeyCrypto();
crypto.KeyMaterial = km;
crypto.InputIsHash = false;
crypto.HashAlgorithm = SBConstants.Unit.SB_ALGORITHM_DGST_SHA256;
TSBPublicKeyVerificationResult vr = crypto.VerifyDetached(inputStream, sigStream);
The inputStream parameter shall contain the hash of the signed data if InputIsHash is true, or the data itself if InputIsHash is true.
The result (vr) will have one of the following values: