Sample code for 30+ languages & platforms
Objective-C

Set the JWS Protected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetProtectedHeader, which sets the integrity-protected header for a signer from a JsonObject. The header specifies the signature algorithm (alg).

Background. The protected header is covered by the signature, so it cannot be altered without invalidating the JWS. It is configured before creating the JWS.

Chilkat Objective-C Downloads

Objective-C
#import <CkoJws.h>
#import <CkoJsonObject.h>

BOOL success = NO;

CkoJws *jws = [[CkoJws alloc] init];

//  Build the JWS protected header.  The "alg" member names the signature algorithm.
CkoJsonObject *header = [[CkoJsonObject alloc] init];
[header UpdateString: @"alg" value: @"HS256"];

//  Set the protected header for signer index 0.  The protected header is integrity-protected: it is
//  covered by the signature.
success = [jws SetProtectedHeader: [NSNumber numberWithInt: 0] json: header];
if (success == NO) {
    NSLog(@"%@",jws.LastErrorText);
    return;
}

NSLog(@"%@",@"Protected header set.");