This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.timby.crypto; | |
import org.timby.util.TweetNaclFast; | |
import java.security.GeneralSecurityException; | |
import java.util.Arrays; | |
import ove.crypto.digest.Blake2b; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Typeface; | |
import android.support.v4.util.SimpleArrayMap; | |
public class TypefaceHelper { | |
private static final SimpleArrayMap<String, Typeface> cache = new SimpleArrayMap<>(); | |
public static Typeface get(Context c, String name) { | |
synchronized (cache) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Cipher createCipher(int mode,SecretKey key,String iv) throws Exception { | |
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC"); | |
cipher.init( | |
Cipher.DECRYPT_MODE, | |
new SecretKeySpec(key, "AES"), | |
new IvParameterSpec(Util.HexEncoder.toByte(iv)) | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = in.read(buffer)) >= 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
random.nextBytes(iv); | |
return iv; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
random.nextBytes(salt); | |
String saltHex = Util.HexEncoder.toHex(salt); | |
return saltHex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://play.google.com/store/apps/details?id=com.myitprovider.pesabox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StringRequest loginReq = new StringRequest(Method.GET, | |
URL, new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
respnse=response; | |
} | |
}, new Response.ErrorListener() { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ujuzicode.repocode; | |
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import com.android.volley.toolbox.HurlStack; | |
import com.squareup.okhttp.OkHttpClient; | |
/** |