Skip to content

Instantly share code, notes, and snippets.

View NaserKhoshfetrat's full-sized avatar

Naser Khoshfetrat NaserKhoshfetrat

View GitHub Profile
import android.content.Intent
import android.text.Html
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
class ShareUtils constructor(val activity: AppCompatActivity) {
companion object : SingletonHolder<ShareUtils, AppCompatActivity>(::ShareUtils)
fun shareHtmlMessage(shareSubject: String?, shareBodyHtml: String?) {
open class SingletonHolder<out T, in A>(private val constructor: (A) -> T) {
@Volatile
private var instance: T? = null
fun getInstance(arg: A): T {
return when {
instance != null -> instance!!
else -> synchronized(this) {
if (instance == null) instance = constructor(arg)
import android.content.Context;
import android.content.SharedPreferences;
public class SharedPreferencesUtils {
private final SharedPreferences preferences;
public SharedPreferencesUtils(SharedPreferences preferences) {
this.preferences = preferences;
}
import android.content.Context;
import android.content.SharedPreferences;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKey;
import com.package.package.BuildConfig;
public class EncryptorAesGcmPasswordFile{
public static byte[] encrypt(byte[] pText, String password) throws Exception {
//...
// prefix IV and Salt to cipher text
byte[] cipherTextWithIvSalt = ByteBuffer.allocate(iv.length + salt.length + cipherText.length)
.put(iv)
.put(salt)
.put(cipherText)
package com.mkyong.crypto.utils;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
package com.mkyong.crypto.encryptor;
import com.mkyong.crypto.utils.CryptoUtils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
package com.mkyong.crypto.encryptor;
import com.mkyong.crypto.utils.CryptoUtils;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@NaserKhoshfetrat
NaserKhoshfetrat / AES.java
Created November 11, 2021 10:00 — forked from Anass-ABEA/AES.java
AES ENCRYPTION
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.GCMParameterSpec;
import java.util.Base64;
/**
* Possible KEY_SIZE values are 128, 192 and 256
* Possible T_LEN values are 128, 120, 112, 104 and 96
*/
@NaserKhoshfetrat
NaserKhoshfetrat / RSA.java
Created November 11, 2021 09:57 — forked from Anass-ABEA/RSA.java
helper methods to encode and decode Strings using the Base64 encoder and decoder
import javax.crypto.Cipher;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;
/**
* @author Anass AIT BEN EL ARBI
* <ul>