Azure Key Vault: Sign a SHA-256 Digest and Verify RS256
See more Azure Key Vault Examples
Requires Chilkat 11.6.0 or later. Keep qa_data/azure/keyvault.json and token/PFX files private, outside web content and source control, with access restricted to the application identity. Use placeholders replaced by your configuration, never commit credentials. Create output directories before running file-writing examples. These examples target Azure public-cloud vaults, not Managed HSM or sovereign-cloud endpoints.
Uses HTTPS and Key Vault data-plane API 2026-04-01. Configure vault_name and first run the client-credentials token example. It writes access_token and an expires_at UTC timestamp to qa_data/tokens/azureKeyVaultToken.json. Each request checks expiration; refresh is explicit. The sample stops on errors and does not retry. Production callers should handle 429/Retry-After and transient failures with bounded backoff, and reconcile uncertain writes. Redirects are disabled.
Set cert_name and an explicit cert_version. Retrieves that public certificate, follows its returned versioned kid, signs a SHA-256 digest using RS256 (RSA PKCS#1 v1.5), and verifies the signature locally. The request and response use base64url, while certificate DER uses standard base64. Requires certificates/get and keys/sign; local verification needs no keys/verify permission. Only the digest is sent to the sign operation. Signature verification does not establish certificate trust, revocation status, or signing time.
Chilkat Objective-C Downloads
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <CkoHttpRequest.h>
#import <CkoHttpResponse.h>
#import <CkoDateTime.h>
#import <NSString.h>
#import <CkoCert.h>
#import <CkoCrypt2.h>
#import <CkoRsa.h>
BOOL success = NO;
CkoStringBuilder *stringCompare = [[CkoStringBuilder alloc] init];
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Keep this configuration private, outside public web content and source control.
CkoJsonObject *config = [[CkoJsonObject alloc] init];
config.Strict = YES;
success = [config LoadFile: @"qa_data/azure/keyvault.json"];
if (success != YES) {
NSLog(@"%@",@"Could not load private Key Vault configuration.");
return;
}
[stringCompare SetString: [config StringOf: @"vault_name"]];
BOOL stringMatch1 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"vault_name"] intValue] != 1) || (stringMatch1 == YES)) {
NSLog(@"%@",@"Missing or invalid vault_name.");
return;
}
CkoStringBuilder *validate1 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet1 = [[CkoStringBuilder alloc] init];
success = [validate1 Append: [config StringOf: @"vault_name"]];
if (success != YES) {
NSLog(@"%@",@"Could not validate vault_name.");
return;
}
success = [alphabet1 Append: @"abcdefghijklmnopqrstuvwxyz0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate1.Length intValue] < 3) || ([validate1.Length intValue] > 24)) {
NSLog(@"%@",@"Invalid vault_name length.");
return;
}
int charIndex1 = 0;
while ((charIndex1 < [validate1.Length intValue])) {
if ([alphabet1 Contains: [validate1 GetRange: [NSNumber numberWithInt: charIndex1] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in vault_name.");
return;
}
charIndex1 = charIndex1 + 1;
}
CkoStringBuilder *vaultName = [[CkoStringBuilder alloc] init];
[vaultName Append: [config StringOf: @"vault_name"]];
CkoStringBuilder *letters = [[CkoStringBuilder alloc] init];
[letters Append: @"abcdefghijklmnopqrstuvwxyz"];
if (([letters Contains: [vaultName GetRange: [NSNumber numberWithInt: 0] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) || ([vaultName EndsWith: @"-" caseSensitive: YES] == YES) || ([vaultName Contains: @"--" caseSensitive: YES] == YES)) {
NSLog(@"%@",@"Invalid vault_name.");
return;
}
CkoStringBuilder *origin = [[CkoStringBuilder alloc] init];
success = [origin Append: @"https://"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [origin Append: [config StringOf: @"vault_name"]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [origin Append: @".vault.azure.net"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
CkoHttp *http = [[CkoHttp alloc] init];
http.RequireSslCertVerify = YES;
http.FollowRedirects = NO;
http.ConnectTimeout = [NSNumber numberWithInt:20];
http.ReadTimeout = [NSNumber numberWithInt:60];
http.VerboseLogging = NO;
CkoHttpRequest *request = [[CkoHttpRequest alloc] init];
request.HttpVerb = @"GET";
CkoHttpResponse *response = [[CkoHttpResponse alloc] init];
CkoJsonObject *result = [[CkoJsonObject alloc] init];
result.Strict = YES;
// First run Get a Key Vault access token.
CkoJsonObject *token = [[CkoJsonObject alloc] init];
token.Strict = YES;
success = [token LoadFile: @"qa_data/tokens/azureKeyVaultToken.json"];
if (success != YES) {
NSLog(@"%@",@"Could not read the private token file.");
return;
}
[stringCompare SetString: [token StringOf: @"access_token"]];
BOOL stringMatch2 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[token JsonTypeOf: @"access_token"] intValue] != 1) || (stringMatch2 == YES)) {
NSLog(@"%@",@"Missing or invalid access_token.");
return;
}
[stringCompare SetString: [token StringOf: @"expires_at"]];
BOOL stringMatch3 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[token JsonTypeOf: @"expires_at"] intValue] != 1) || (stringMatch3 == YES)) {
NSLog(@"%@",@"Missing or invalid expires_at.");
return;
}
CkoDateTime *expires = [[CkoDateTime alloc] init];
CkoDateTime *now = [[CkoDateTime alloc] init];
success = [expires SetFromTimestamp: [token StringOf: @"expires_at"]];
if (success != YES) {
NSLog(@"%@",@"Invalid token expiration.");
return;
}
http.AuthToken = [token StringOf: @"access_token"];
[stringCompare SetString: [config StringOf: @"cert_name"]];
BOOL stringMatch4 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"cert_name"] intValue] != 1) || (stringMatch4 == YES)) {
NSLog(@"%@",@"Missing or invalid cert_name.");
return;
}
CkoStringBuilder *validate2 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet2 = [[CkoStringBuilder alloc] init];
success = [validate2 Append: [config StringOf: @"cert_name"]];
if (success != YES) {
NSLog(@"%@",@"Could not validate cert_name.");
return;
}
success = [alphabet2 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate2.Length intValue] < 1) || ([validate2.Length intValue] > 127)) {
NSLog(@"%@",@"Invalid cert_name length.");
return;
}
int charIndex2 = 0;
while ((charIndex2 < [validate2.Length intValue])) {
if ([alphabet2 Contains: [validate2 GetRange: [NSNumber numberWithInt: charIndex2] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in cert_name.");
return;
}
charIndex2 = charIndex2 + 1;
}
[stringCompare SetString: [config StringOf: @"cert_version"]];
BOOL stringMatch5 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[config JsonTypeOf: @"cert_version"] intValue] != 1) || (stringMatch5 == YES)) {
NSLog(@"%@",@"Missing or invalid cert_version.");
return;
}
CkoStringBuilder *validate3 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet3 = [[CkoStringBuilder alloc] init];
success = [validate3 Append: [config StringOf: @"cert_version"]];
if (success != YES) {
NSLog(@"%@",@"Could not validate cert_version.");
return;
}
success = [alphabet3 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate3.Length intValue] < 1) || ([validate3.Length intValue] > 127)) {
NSLog(@"%@",@"Invalid cert_version length.");
return;
}
int charIndex3 = 0;
while ((charIndex3 < [validate3.Length intValue])) {
if ([alphabet3 Contains: [validate3 GetRange: [NSNumber numberWithInt: charIndex3] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in cert_version.");
return;
}
charIndex3 = charIndex3 + 1;
}
CkoStringBuilder *certificateBase = [[CkoStringBuilder alloc] init];
success = [certificateBase Append: [origin GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [certificateBase Append: @"/certificates/"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [certificateBase Append: [config StringOf: @"cert_name"]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
CkoStringBuilder *bundlePrefix = [[CkoStringBuilder alloc] init];
success = [bundlePrefix Append: [certificateBase GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [bundlePrefix Append: @"/"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
CkoStringBuilder *pinnedCertId = [[CkoStringBuilder alloc] init];
success = [pinnedCertId Append: [bundlePrefix GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [pinnedCertId Append: [config StringOf: @"cert_version"]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
CkoStringBuilder *getUrl = [[CkoStringBuilder alloc] init];
success = [getUrl Append: [pinnedCertId GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [getUrl Append: @"?api-version=2026-04-01"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [now SetFromCurrentSystemTime];
if (success != YES) {
NSLog(@"%@",@"Could not read current time.");
return;
}
if ([[expires DiffSeconds: now] intValue] <= 60) {
NSLog(@"%@",@"Token is expired or near expiration. Obtain a new token before continuing.");
return;
}
success = [http HttpReq: [getUrl GetAsString] request: request response: response];
if (success != YES) {
NSLog(@"%@",@"Request did not complete; inspect diagnostics privately.");
return;
}
if ([response.StatusCode intValue] != 200) {
NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
// Do not print full response bodies, tokens, or diagnostic logs.
NSLog(@"%@",@"Request failed. Inspect private diagnostics; reconcile writes before retrying.");
return;
}
success = [result Load: response.BodyStr];
if (success != YES) {
NSLog(@"%@",@"Expected a well-formed JSON response.");
return;
}
[stringCompare SetString: [result StringOf: @"id"]];
BOOL stringMatch6 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"id"] intValue] != 1) || (stringMatch6 == YES)) {
NSLog(@"%@",@"Missing or invalid id.");
return;
}
[stringCompare SetString: [result StringOf: @"kid"]];
BOOL stringMatch7 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"kid"] intValue] != 1) || (stringMatch7 == YES)) {
NSLog(@"%@",@"Missing or invalid kid.");
return;
}
[stringCompare SetString: [result StringOf: @"cer"]];
BOOL stringMatch8 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"cer"] intValue] != 1) || (stringMatch8 == YES)) {
NSLog(@"%@",@"Missing or invalid cer.");
return;
}
CkoStringBuilder *certificateVersionId = [[CkoStringBuilder alloc] init];
success = [certificateVersionId Append: [result StringOf: @"id"]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
if ([certificateVersionId StartsWith: [bundlePrefix GetAsString] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Returned identifier is outside the expected vault/resource.");
return;
}
NSString *certificateVersion = [certificateVersionId GetRange: bundlePrefix.Length numChars: [NSNumber numberWithInt: ([certificateVersionId.Length intValue] - [bundlePrefix.Length intValue])] removeFlag: NO];
CkoStringBuilder *validate7 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet7 = [[CkoStringBuilder alloc] init];
success = [validate7 Append: certificateVersion];
if (success != YES) {
NSLog(@"%@",@"Could not validate resource identifier.");
return;
}
success = [alphabet7 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate7.Length intValue] < 1) || ([validate7.Length intValue] > 127)) {
NSLog(@"%@",@"Invalid resource identifier length.");
return;
}
int charIndex7 = 0;
while ((charIndex7 < [validate7.Length intValue])) {
if ([alphabet7 Contains: [validate7 GetRange: [NSNumber numberWithInt: charIndex7] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in resource identifier.");
return;
}
charIndex7 = charIndex7 + 1;
}
CkoStringBuilder *keyPrefix = [[CkoStringBuilder alloc] init];
success = [keyPrefix Append: [origin GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [keyPrefix Append: @"/keys/"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
CkoStringBuilder *keyTailId = [[CkoStringBuilder alloc] init];
success = [keyTailId Append: [result StringOf: @"kid"]];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
if ([keyTailId StartsWith: [keyPrefix GetAsString] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Returned identifier is outside the expected vault/resource.");
return;
}
NSString *keyTail = [keyTailId GetRange: keyPrefix.Length numChars: [NSNumber numberWithInt: ([keyTailId.Length intValue] - [keyPrefix.Length intValue])] removeFlag: NO];
CkoStringBuilder *keyTailParts = [[CkoStringBuilder alloc] init];
success = [keyTailParts Append: keyTail];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
NSString *keyTailName = [keyTailParts GetBefore: @"/" removeFlag: NO];
NSString *keyTailVersion = [keyTailParts GetAfterFinal: @"/" removeFlag: NO];
CkoStringBuilder *validate8 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet8 = [[CkoStringBuilder alloc] init];
success = [validate8 Append: keyTailName];
if (success != YES) {
NSLog(@"%@",@"Could not validate resource name.");
return;
}
success = [alphabet8 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate8.Length intValue] < 1) || ([validate8.Length intValue] > 127)) {
NSLog(@"%@",@"Invalid resource name length.");
return;
}
int charIndex8 = 0;
while ((charIndex8 < [validate8.Length intValue])) {
if ([alphabet8 Contains: [validate8 GetRange: [NSNumber numberWithInt: charIndex8] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in resource name.");
return;
}
charIndex8 = charIndex8 + 1;
}
CkoStringBuilder *validate9 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet9 = [[CkoStringBuilder alloc] init];
success = [validate9 Append: keyTailVersion];
if (success != YES) {
NSLog(@"%@",@"Could not validate resource version.");
return;
}
success = [alphabet9 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate9.Length intValue] < 1) || ([validate9.Length intValue] > 127)) {
NSLog(@"%@",@"Invalid resource version length.");
return;
}
int charIndex9 = 0;
while ((charIndex9 < [validate9.Length intValue])) {
if ([alphabet9 Contains: [validate9 GetRange: [NSNumber numberWithInt: charIndex9] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in resource version.");
return;
}
charIndex9 = charIndex9 + 1;
}
CkoStringBuilder *keyTailCanonical = [[CkoStringBuilder alloc] init];
success = [keyTailCanonical Append: keyTailName];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [keyTailCanonical Append: @"/"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [keyTailCanonical Append: keyTailVersion];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
[stringCompare SetString: keyTail];
BOOL stringMatch9 = [stringCompare ContentsEqual: [keyTailCanonical GetAsString] caseSensitive: YES];
if (stringMatch9 != YES) {
NSLog(@"%@",@"Expected a versioned resource identifier.");
return;
}
NSString *certificateId = [result StringOf: @"id"];
NSString *keyId = [result StringOf: @"kid"];
CkoCert *remoteCert = [[CkoCert alloc] init];
success = [remoteCert LoadFromBase64: [result StringOf: @"cer"]];
if (success != YES) {
NSLog(@"%@",@"Could not load the returned public certificate.");
return;
}
[stringCompare SetString: certificateId];
BOOL stringMatch10 = [stringCompare ContentsEqual: [pinnedCertId GetAsString] caseSensitive: YES];
if (stringMatch10 != YES) {
NSLog(@"%@",@"The response is not the requested certificate version.");
return;
}
if ([remoteCert IsRsa] != YES) {
NSLog(@"%@",@"This RS256 example requires an RSA certificate.");
return;
}
NSString *message = @"This is a test";
CkoCrypt2 *hash = [[CkoCrypt2 alloc] init];
hash.Charset = @"utf-8";
hash.HashAlgorithm = @"sha256";
hash.EncodingMode = @"base64url";
NSString *digest = [hash HashStringENC: message];
if (hash.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not hash the message.");
return;
}
CkoJsonObject *body = [[CkoJsonObject alloc] init];
success = [body UpdateString: @"alg" value: @"RS256"];
if (success != YES) {
NSLog(@"%@",@"Could not set alg.");
return;
}
success = [body UpdateString: @"value" value: digest];
if (success != YES) {
NSLog(@"%@",@"Could not set value.");
return;
}
CkoStringBuilder *signUrl = [[CkoStringBuilder alloc] init];
success = [signUrl Append: keyId];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [signUrl Append: @"/sign"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [signUrl Append: @"?api-version=2026-04-01"];
if (success != YES) {
NSLog(@"%@",@"Could not construct URL or identifier.");
return;
}
success = [now SetFromCurrentSystemTime];
if (success != YES) {
NSLog(@"%@",@"Could not read current time.");
return;
}
if ([[expires DiffSeconds: now] intValue] <= 60) {
NSLog(@"%@",@"Token is expired or near expiration. Obtain a new token before continuing.");
return;
}
success = [http HttpJson: @"POST" url: [signUrl GetAsString] json: body contentType: @"application/json" response: response];
if (success != YES) {
NSLog(@"%@",@"Request failed or its outcome is uncertain. Reconcile a write before retrying.");
return;
}
if ([response.StatusCode intValue] != 200) {
NSLog(@"%@%d",@"HTTP status: ",[response.StatusCode intValue]);
NSLog(@"%@%@",@"Request ID: ",[response GetHeaderField: @"x-ms-request-id"]);
// Do not print full response bodies, tokens, or diagnostic logs.
NSLog(@"%@",@"Request failed. Inspect private diagnostics; reconcile writes before retrying.");
return;
}
success = [result Load: response.BodyStr];
if (success != YES) {
NSLog(@"%@",@"Expected a well-formed JSON response.");
return;
}
[stringCompare SetString: [result StringOf: @"kid"]];
BOOL stringMatch11 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"kid"] intValue] != 1) || (stringMatch11 == YES)) {
NSLog(@"%@",@"Missing or invalid kid.");
return;
}
[stringCompare SetString: [result StringOf: @"value"]];
BOOL stringMatch12 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[result JsonTypeOf: @"value"] intValue] != 1) || (stringMatch12 == YES)) {
NSLog(@"%@",@"Missing or invalid value.");
return;
}
[stringCompare SetString: [result StringOf: @"kid"]];
BOOL stringMatch13 = [stringCompare ContentsEqual: keyId caseSensitive: YES];
if (stringMatch13 != YES) {
NSLog(@"%@",@"Signature response refers to another key version.");
return;
}
NSString *signature = [result StringOf: @"value"];
CkoStringBuilder *validate10 = [[CkoStringBuilder alloc] init];
CkoStringBuilder *alphabet10 = [[CkoStringBuilder alloc] init];
success = [validate10 Append: signature];
if (success != YES) {
NSLog(@"%@",@"Could not validate base64url signature.");
return;
}
success = [alphabet10 Append: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"];
if (success != YES) {
NSLog(@"%@",@"Could not initialize validation.");
return;
}
if (([validate10.Length intValue] < 1) || ([validate10.Length intValue] > 2048)) {
NSLog(@"%@",@"Invalid base64url signature length.");
return;
}
int charIndex10 = 0;
while ((charIndex10 < [validate10.Length intValue])) {
if ([alphabet10 Contains: [validate10 GetRange: [NSNumber numberWithInt: charIndex10] numChars: [NSNumber numberWithInt: 1] removeFlag: NO] caseSensitive: YES] != YES) {
NSLog(@"%@",@"Invalid character in base64url signature.");
return;
}
charIndex10 = charIndex10 + 1;
}
CkoRsa *rsa = [[CkoRsa alloc] init];
rsa.Charset = @"utf-8";
rsa.EncodingMode = @"base64url";
success = [rsa SetX509Cert: remoteCert usePrivateKey: NO];
if (success != YES) {
NSLog(@"%@",@"Could not select the public verification key.");
return;
}
success = [rsa VerifyStringENC: message hashAlg: @"sha256" sig: signature];
if (success != YES) {
NSLog(@"%@",@"Signature verification failed.");
return;
}
NSLog(@"%@",@"RS256 signature verified locally with the certificate public key.");
// Verification hashes the original UTF-8 message once. The Sign API receives the digest.