Android™
Android™
RSASSA-PSS Algorithm with SHA256 Hashing
See more RSA Examples
RSA encrypt a SHA256 hash with OAEP padding.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;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkPrivateKey privkey = new CkPrivateKey();
// Load the private key object from a PEM file.
// (To load from a PEM string, call LoadPem instead.)
success = privkey.LoadPemFile("somePath/myPrivateKey.pem");
if (success == false) {
Log.i(TAG, privkey.lastErrorText());
return;
}
CkRsa rsa = new CkRsa();
// Use RSA-PSS by setting PkcsPadding = false
rsa.put_PkcsPadding(false);
// Use SHA256
rsa.put_OaepHash("SHA-256");
rsa.UsePrivateKey(privkey);
// Generate a base64 signature.
rsa.put_EncodingMode("base64");
String sigStr = rsa.signStringENC("String to be signed","SHA-256");
if (rsa.get_LastMethodSuccess() == false) {
Log.i(TAG, rsa.lastErrorText());
return;
}
Log.i(TAG, "Signature: " + sigStr);
}
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."
}
}