Skip to content

Instantly share code, notes, and snippets.

Jaymo /
Created May 8, 2018 14:28
package org.timby.crypto;
import org.timby.util.TweetNaclFast;
import java.util.Arrays;
import ove.crypto.digest.Blake2b;
import android.content.Context;
public class TypefaceHelper {
private static final SimpleArrayMap<String, Typeface> cache = new SimpleArrayMap<>();
public static Typeface get(Context c, String name) {
synchronized (cache) {
public static Cipher createCipher(int mode,SecretKey key,String iv) throws Exception {
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
new SecretKeySpec(key, "AES"),
new IvParameterSpec(Util.HexEncoder.toByte(iv))
private final static int DEFAULT_READ_WRITE_BLOCK_BUFFER_SIZE = 1024;
public static void applyCipher(String inFile, String outFile, Cipher cipher) throws Exception {
CipherInputStream in = new CipherInputStream(new FileInputStream(inFile), cipher);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFile));
byte[] buffer = new byte[DEFAULT_READ_WRITE_BLOCK_BUFFER_SIZE];
int count = 0;
while ((count = >= 0) {
private static final String RANDOM_ALGORITHM = "SHA1PRNG";
public static final int IV_LENGTH = 16;
private byte[] generateIv() throws NoSuchAlgorithmException, NoSuchProviderException {
SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
byte[] iv = new byte[IV_LENGTH];
return iv;
public static final int SALT_LENGTH = 256;
private static final String RANDOM_ALGORITHM = "SHA1PRNG";
public String generateSalt() throws CryptoException {
try {
SecureRandom random = SecureRandom.getInstance(RANDOM_ALGORITHM);
byte[] salt = new byte[SALT_LENGTH];
String saltHex = Util.HexEncoder.toHex(salt);
return saltHex;
public static final int PBE_ITERATION_COUNT = 10000; //Am not sure on this size and low end devices. I should test more to prevent lag
private static final String PBE_ALGORITHM = "PBKDF2WithHmacSHA1";
public static final String PROVIDER = "BC";
private static final String SECRET_KEY_ALGORITHM = "AES/GCM/NoPadding;
public static SecretKey getSecretKey(String password, String salt) throws CryptoException {
try {
PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), Util.HexEncoder.toByte(salt), PBE_ITERATION_COUNT, 256);
SecretKeyFactory factory = SecretKeyFactory.getInstance(PBE_ALGORITHM, PROVIDER);
SecretKey tmp = factory.generateSecret(pbeKeySpec);
Jaymo / file.rb
Created August 9, 2014 21:02
Take a look at "PesaBox"
Jaymo /
Created June 16, 2014 08:51
Volley: passing parameters in a string request
StringRequest loginReq = new StringRequest(Method.GET,
URL, new Response.Listener<String>() {
public void onResponse(String response) {
}, new Response.ErrorListener() {
Jaymo /
Last active August 29, 2015 14:02
A `HttpStack` implementation for Volley that uses OkHttp 2.0 as its transport.
package com.ujuzicode.repocode;
import com.squareup.okhttp.OkHttpClient;