Android Open Source - SecNote Note Utility






From Project

Back to project page SecNote.

License

The source code is released under:

Apache License

If you think the Android project SecNote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.baraccasoftware.securenotes.object;
//from  w  w  w .  j ava 2 s  . c om
import android.content.Context;
import android.util.Base64;
import android.util.Log;

/**
 * Created by angelo on 25/02/14.
 */
public class NoteUtility {

    /**
     * this method creates an encrypted Note to store into DB
     * @param toEncrypt
     * @return Encrypted note
     */
    public static Note encryptNote(Note toEncrypt, Context mContext){

        PBKDF2Encryptor encryptor = new PBKDF2Encryptor();

        PasswordPreference preference = new PasswordPreference(mContext);
        Encryptor.password = preference.getPassword();

        String nameEn = encryptor.encrypt(toEncrypt.getmName(),Encryptor.password);
        String descEn = encryptor.encrypt(toEncrypt.getmDesc(),Encryptor.password);

        Note encrypted;
        if(toEncrypt.getmImage().length>1){
            //criptiamo immagine
            String imgString = Base64.encodeToString(toEncrypt.getmImage(), Base64.DEFAULT);
            String enimgString = encryptor.encrypt(imgString,Encryptor.password);
            byte[] imgEn = enimgString.getBytes();

            //Note encrypted = new Note(toEncrypt.getmId(),nameEn,descEn,toEncrypt.getmDate(),
            //      toEncrypt.getImageLen(),toEncrypt.getmImage());
            encrypted = new Note(toEncrypt.getmId(),nameEn,descEn,toEncrypt.getmDate(),
                    imgEn);
        }else{
            encrypted = new Note(toEncrypt.getmId(),nameEn,descEn,toEncrypt.getmDate()
                    ,toEncrypt.getmImage());
        }
        return encrypted;
    }

    /**
     * this method creates a decrypted note loaded from db
     * @param toDecrypt
     * @return decrypted note
     */
    public static Note decryptNote(Note toDecrypt,Context mContext){
        PBKDF2Encryptor encryptor = new PBKDF2Encryptor();
        if(Encryptor.password == null){
            Log.d("FFFFFFFFFFFFF","PASSWORD NULL");
            PasswordPreference preference = new PasswordPreference(mContext);
            Encryptor.password = preference.getPassword();
            Log.d("PASSWORD IN PREFERENCE", Encryptor.password);
        }

        String nameEn = encryptor.decrypt(toDecrypt.getmName(), Encryptor.password);
        String descEn = encryptor.decrypt(toDecrypt.getmDesc(), Encryptor.password);

        Note decrypted;

        decrypted = new Note(toDecrypt.getmId(),nameEn,descEn,toDecrypt.getmDate(),
                toDecrypt.getmImage());
        //}
        return decrypted;
    }


    public static byte[] decryptImg(byte[] imgToDecrypt,Context mContext){
        PBKDF2Encryptor encryptor = new PBKDF2Encryptor();
        PasswordPreference preference = new PasswordPreference(mContext);
        Encryptor.password = preference.getPassword();
        byte[] imgEncryptedFromNote = imgToDecrypt;
        String enimgString = new String(imgEncryptedFromNote);
        String imgString = encryptor.decrypt(enimgString, Encryptor.password);
        return Base64.decode(imgString, Base64.DEFAULT);
    }
}




Java Source Code List

com.baraccasoftware.securenotes.app.ExportDialogFragment.java
com.baraccasoftware.securenotes.app.ImportDialogFragment.java
com.baraccasoftware.securenotes.app.InfoActivity.java
com.baraccasoftware.securenotes.app.InfoFragment.java
com.baraccasoftware.securenotes.app.LockedAppFragment.java
com.baraccasoftware.securenotes.app.LogInFragment.java
com.baraccasoftware.securenotes.app.MainActivity.java
com.baraccasoftware.securenotes.app.NoteDetailActivity.java
com.baraccasoftware.securenotes.app.NoteDetailFragment.java
com.baraccasoftware.securenotes.app.NoteListActivity.java
com.baraccasoftware.securenotes.app.NoteListFragment.java
com.baraccasoftware.securenotes.app.RegisterFragment.java
com.baraccasoftware.securenotes.app.SetPasswordFragment.java
com.baraccasoftware.securenotes.app.SettingsActivity.java
com.baraccasoftware.securenotes.app.SettingsFragment.java
com.baraccasoftware.securenotes.exception.LoadBitmapException.java
com.baraccasoftware.securenotes.object.ActivityUtilityInterface.java
com.baraccasoftware.securenotes.object.BitmapUtility.java
com.baraccasoftware.securenotes.object.Crypto.java
com.baraccasoftware.securenotes.object.DAO.java
com.baraccasoftware.securenotes.object.Encryptor.java
com.baraccasoftware.securenotes.object.ImageLoader.java
com.baraccasoftware.securenotes.object.NoteUtility.java
com.baraccasoftware.securenotes.object.Note.java
com.baraccasoftware.securenotes.object.PBKDF2Encryptor.java
com.baraccasoftware.securenotes.object.PasswordPreference.java
com.baraccasoftware.securenotes.object.SecureDatabaseHelper.java
com.baraccasoftware.securenotes.widget.NoteAdapter.java
com.baraccasoftware.securenotes.widget.SlidingDrawer.java
com.baraccasoftware.securenotes.widget.SwipeDismissListViewTouchListener.java
com.baraccasoftware.securenotes.widget.UndoBarController.java