ifRSA

Implemented by

NameDescription
roRSAThe RSA component provides an interface to the OpenSSL RSA library of signing algorithms

Supported methods

SetPrivateKey(keyFileName as String) as Integer

Description

Specifies the private key to use for signing.

Parameters

NameTypeDescription
keyFileNameStringSpecifies the private key to be used for signing. The file name should specify a path, either in the package or a temp path.

Return Value

  • 1 = The key is valid.
  • 0 = The file does not contain a valid key.
  • -1 = The file was not found.

SetPublicKey(keyFileName as String) as Integer

Specifies the public key to be used for verification.

Parameters

NameTypeDescription
keyFileNameStringSpecifies the public key to be used for signing. The file name should specify a path, either in the package or a temp path.

Return Value

  • 1 = The key is valid.
  • 0 = The file does not contain a valid key.
  • -1 = The file was not found.

SetDigestAlgorithm(digestAlgorithm as String) as Boolean

Specifies the digest algorithm to use for signing and verification.

NameTypeDescription
digestAlgorithmStringAn openssl string with the digest to be used. Common digest algorithms are "sha1", "ripemd160", and "md5".

Return Value

A flag indicating whether the algorithm was successfully set (true) or the string was not recognized (false).

Sign(digest as Object) as Object

Description

Generates a signature based on the specified digest.

Parameters

NameTypeDescription
digestroByteArray ObjectThe roByteArray to be signed. Errors will be printed in the BrightScript console. If the digest algorithm is not set (using SetDigestAlgorithm) before calling Sign(), the digest is not encapsulated. This would be equivalent to simply calling the openssl function RSA_private_encrypt()

Return Value

An roByteArray containing the signature, or invalid if an error occurred. Typical values include the following:

  • digest is empty
  • SetPrivateKey() was not yet called
  • out of memory
  • the digest could not be signed

Verify(digest as Object, signature as Object) as Integer

Description

Verifies the given digest and signature. Both digest and signature should be roByteArrays. If the digest algorithm is not set (using the SetDigestAlgorithm method) before calling Verify(), the digest associated with the signature is not expected to be encapsulated. This would be equivalent to simply calling the openssl function RSA_public_decrypt(signature) and then comparing the result with the digest

Parameters

NameTypeDescription
digestroByteArray ObjectThe digest to be verified.
signatureroByteArray ObjectThe signature to be verified.

Return Value

Indicates the result of the validation. This may be one of the following values:

  • 1 = The signature matches.
  • -1 = The SetPublicKey() method was not yet called.
  • -2 = The digest is empty.
  • -3 = There is not enough memory.
  • 0 = The signature does not match.