Android™
Android™
Example: Crypt2.HashStringENC method
Demonstrates how to call the HashStringENC method.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);
CkCrypt2 crypt = new CkCrypt2();
String s = "får";
// The string "får" in utf-8 is composed of these bytes: 0x66 0xC3 0xA5 0x72
crypt.put_Charset("utf-8");
crypt.put_EncodingMode("hex_lower");
crypt.put_HashAlgorithm("sha256");
// Get the hex string for the sha-256 hash of the utf-8 byte representation of the string
String hashStr = crypt.hashStringENC(s);
Log.i(TAG, hashStr);
// Output:
// cb8f773dd592337ed7f928012a60f48e1efb357beeda124a54461410e216fece
}
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."
}
}