Android™
Android™
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 Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
CkJws jws = new CkJws();
// Build the JWS protected header. The "alg" member names the signature algorithm.
CkJsonObject header = new CkJsonObject();
header.UpdateString("alg","HS256");
// Set the protected header for signer index 0. The protected header is integrity-protected: it is
// covered by the signature.
success = jws.SetProtectedHeader(0,header);
if (success == false) {
Log.i(TAG, jws.lastErrorText());
return;
}
Log.i(TAG, "Protected header set.");
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}