Skip to content

Instantly share code, notes, and snippets.

View jetrubyshared's full-sized avatar

JetRuby Agency jetrubyshared

View GitHub Profile
public class TracksDataUtil {
private static String[] bandNames = {
"Protest The Hero",
"The Fall Of Troy",
"Erra",
"Periphery",
"Napoleon",public class TracksDataUtil {
private static String[] bandNames = {
"Protest The Hero",
"The Fall Of Troy",
public class Track {
private String artist;
private String title;
private boolean isLiked;
private boolean isPlaying;
public Track(String artist, String title) {
this.artist = artist;
this.title = title;
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
private static String decryptString(String string, Cipher cipher) {
try {
byte[] bytes = Base64.decode(string, Base64.NO_WRAP);
return new String(cipher.doFinal(bytes));
} catch (IllegalBlockSizeException | BadPaddingException exception) {
exception.printStackTrace();
}
return null;
}
private static String encryptString(String string) {
try {
if (initKeyStore() && initCipher() && initKey() && initCipherMode(Cipher.ENCRYPT_MODE)) {
byte[] bytes = sCipher.doFinal(string.getBytes());
return Base64.encodeToString(bytes, Base64.NO_WRAP);
}
} catch (IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
}
return null;
private static boolean initCipherMode(int mode) {
try {
sKeyStore.load(null);
switch (mode) {
case Cipher.ENCRYPT_MODE:
PublicKey key = sKeyStore.getCertificate(KEY_ALIAS).getPublicKey();
PublicKey unrestricted = KeyFactory.getInstance(key.getAlgorithm()).generatePublic(new X509EncodedKeySpec(key.getEncoded()));
OAEPParameterSpec spec = new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT);
sCipher.init(mode, unrestricted, spec);
break;
private static boolean initCipherMode(int mode) {
sCipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
try {
sKeyPairGenerator.initialize(new KeyGenParameterSpec.Builder(KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA512)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_OAEP)
.setUserAuthenticationRequired(true)
.build());
sKeyPairGenerator.generateKeyPair();
return true;
} catch (InvalidAlgorithmParameterException e) {
sKeyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA, KEY_STORE);