Skip to content

Instantly share code, notes, and snippets.

Enrique López Mañas kikoso

Block or report user

Report or block kikoso

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View callingNative.java
byte[] keyStart = getSecretKey().getBytes();
View ndkFunction.java
Java_com_example_exampleApp_ExampleClass_getSecretKey( JNIEnv* env,
jobject thiz )
{
return (*env)->NewStringUTF(env, "mySecretKey".");
}
View loadingANativeFunction.java
static {
System.loadLibrary("library-name");
}
public native String getSecretKey();
View usingEncryptAndDecrypt.java
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
byte[] keyStart = "encryption key".getBytes();
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(keyStart);
kgen.init(128, sr);
SecretKey skey = kgen.generateKey();
View encryptAndDecrypt.java
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
View firebaseThirdExample.java
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.i("MyApp","Data changed");
}
@Override
public void onCancelled(DatabaseError databaseError) {
View firebaseSecondExample.java
FirebaseDatabase database = FirebaseDatabase.getInstance();
database.getReference().push().setValue("Hello world");
View firebaseFirstExample.java
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
View Immutablestar.java
public final class Star {
/**
* Final and private attributes
*/
private final double mass;
private final String name;
private final Date dateOfDiscovery;
public Star (double aMass, String aName, Date aDateOfDiscovery) {
View Immutable Star
public final class Star {
/**
* Final and private attributes
*/
private final double mass;
private final String name;
private final Date fDateOfDiscovery;
public Planet (double aMass, String aName, Date aDateOfDiscovery) {
You can’t perform that action at this time.