package com.incotalk; import com.facebook.crypto.exception.KeyChainException; import com.facebook.crypto.keychain.KeyChain; import com.facebook.crypto.keychain.SecureRandomFix; import java.security.SecureRandom; import java.util.Arrays; import android.content.Context; import android.content.SharedPreferences; import android.util.Base64; import android.util.Log; import com.facebook.crypto.cipher.NativeGCMCipher; import com.facebook.crypto.mac.NativeMac; /** * Created by TheKing on 2014-12-29. */ public class CustomSharedPrefsBackedKeyChain implements KeyChain { // Visible for testing. private final SharedPreferences mSharedPreferences; protected byte[] mCipherKey; protected boolean mSetCipherKey; protected byte[] mMacKey; protected boolean mSetMacKey; private static final SecureRandomFix sSecureRandomFix = new SecureRandomFix(); Log.d(log, "CustomSharedPrefsBackedKeyChain"); //this.key = key; } @Override public synchronized byte[] getCipherKey() throws KeyChainException { if (!mSetCipherKey) { mCipherKey = maybeGenerateKey(CIPHER_KEY_PREF, NativeGCMCipher.KEY_LENGTH); } mSetCipherKey = true; return mCipherKey; } @Override public byte[] getMacKey() throws KeyChainException { if (!mSetMacKey) { mMacKey = maybeGenerateKey(MAC_KEY_PREF, NativeMac.KEY_LENGTH); } mSetMacKey = true; return mMacKey; } @Override public byte[] getNewIV() throws KeyChainException { sSecureRandomFix.tryApplyFixes(); byte[] iv = new byte[NativeGCMCipher.IV_LENGTH]; mSecureRandom.nextBytes(iv); return iv; } @Override public synchronized void destroyKeys() { mSetCipherKey = false; mSetMacKey = false; mCipherKey = null; mMacKey = null; SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.remove(CIPHER_KEY_PREF); editor.remove(MAC_KEY_PREF); editor.commit(); } /** * Generates a key associated with a preference. */ if(length == NativeGCMCipher.KEY_LENGTH) base64Key = key; else if (base64Key == null) { // Generate key if it doesn't exist. return generateAndSaveKey(pref, length); } else { return decodeFromPrefs(base64Key); } } sSecureRandomFix.tryApplyFixes(); byte[] key = new byte[length]; if(length == NativeGCMCipher.KEY_LENGTH) key = this.key.getBytes(); else key = (this.key + this.key + this.key +this.key).getBytes(); mSecureRandom.nextBytes(key); // Store the session key. SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString( pref, encodeForPrefs(key)); editor.commit(); Log.d(log, key.toString()); return key; } /** * Visible for testing. */ keyString = this.key; if (keyString == null) { return null; } Log.d(log, keyString.toString()); return Base64.decode(keyString, Base64.DEFAULT); } /** * Visible for testing. */ key = (this.key).getBytes(); if (key == null ) { return null; } return Base64.encodeToString(key, Base64.DEFAULT); } }
Standard input is empty
Main.java:19: error: class CustomSharedPrefsBackedKeyChain is public, should be declared in a file named CustomSharedPrefsBackedKeyChain.java public class CustomSharedPrefsBackedKeyChain implements KeyChain { ^ Main.java:3: error: package com.facebook.crypto.exception does not exist import com.facebook.crypto.exception.KeyChainException; ^ Main.java:4: error: package com.facebook.crypto.keychain does not exist import com.facebook.crypto.keychain.KeyChain; ^ Main.java:5: error: package com.facebook.crypto.keychain does not exist import com.facebook.crypto.keychain.SecureRandomFix; ^ Main.java:8: error: package android.content does not exist import android.content.Context; ^ Main.java:9: error: package android.content does not exist import android.content.SharedPreferences; ^ Main.java:10: error: package android.util does not exist import android.util.Base64; ^ Main.java:11: error: package android.util does not exist import android.util.Log; ^ Main.java:13: error: package com.facebook.crypto.cipher does not exist import com.facebook.crypto.cipher.NativeGCMCipher; ^ Main.java:14: error: package com.facebook.crypto.mac does not exist import com.facebook.crypto.mac.NativeMac; ^ Main.java:19: error: cannot find symbol public class CustomSharedPrefsBackedKeyChain implements KeyChain { ^ symbol: class KeyChain Main.java:25: error: cannot find symbol private final SharedPreferences mSharedPreferences; ^ symbol: class SharedPreferences location: class CustomSharedPrefsBackedKeyChain Main.java:35: error: cannot find symbol private static final SecureRandomFix sSecureRandomFix = new SecureRandomFix(); ^ symbol: class SecureRandomFix location: class CustomSharedPrefsBackedKeyChain Main.java:38: error: cannot find symbol public CustomSharedPrefsBackedKeyChain(Context context, String key) { ^ symbol: class Context location: class CustomSharedPrefsBackedKeyChain Main.java:46: error: cannot find symbol public synchronized byte[] getCipherKey() throws KeyChainException { ^ symbol: class KeyChainException location: class CustomSharedPrefsBackedKeyChain Main.java:55: error: cannot find symbol public byte[] getMacKey() throws KeyChainException { ^ symbol: class KeyChainException location: class CustomSharedPrefsBackedKeyChain Main.java:64: error: cannot find symbol public byte[] getNewIV() throws KeyChainException { ^ symbol: class KeyChainException location: class CustomSharedPrefsBackedKeyChain Main.java:88: error: cannot find symbol private byte[] maybeGenerateKey(String pref, int length) throws KeyChainException { ^ symbol: class KeyChainException location: class CustomSharedPrefsBackedKeyChain Main.java:104: error: cannot find symbol private byte[] generateAndSaveKey(String pref, int length) throws KeyChainException { ^ symbol: class KeyChainException location: class CustomSharedPrefsBackedKeyChain Main.java:35: error: cannot find symbol private static final SecureRandomFix sSecureRandomFix = new SecureRandomFix(); ^ symbol: class SecureRandomFix location: class CustomSharedPrefsBackedKeyChain Main.java:39: error: cannot find symbol Log.d(log, "CustomSharedPrefsBackedKeyChain"); ^ symbol: variable Log location: class CustomSharedPrefsBackedKeyChain Main.java:40: error: cannot find symbol mSharedPreferences = context.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); ^ symbol: variable Context location: class CustomSharedPrefsBackedKeyChain Main.java:48: error: cannot find symbol mCipherKey = maybeGenerateKey(CIPHER_KEY_PREF, NativeGCMCipher.KEY_LENGTH); ^ symbol: variable NativeGCMCipher location: class CustomSharedPrefsBackedKeyChain Main.java:45: error: method does not override or implement a method from a supertype @Override ^ Main.java:57: error: cannot find symbol mMacKey = maybeGenerateKey(MAC_KEY_PREF, NativeMac.KEY_LENGTH); ^ symbol: variable NativeMac location: class CustomSharedPrefsBackedKeyChain Main.java:54: error: method does not override or implement a method from a supertype @Override ^ Main.java:66: error: cannot find symbol byte[] iv = new byte[NativeGCMCipher.IV_LENGTH]; ^ symbol: variable NativeGCMCipher location: class CustomSharedPrefsBackedKeyChain Main.java:63: error: method does not override or implement a method from a supertype @Override ^ Main.java:79: error: package SharedPreferences does not exist SharedPreferences.Editor editor = mSharedPreferences.edit(); ^ Main.java:71: error: method does not override or implement a method from a supertype @Override ^ Main.java:91: error: cannot find symbol if(length == NativeGCMCipher.KEY_LENGTH) ^ symbol: variable NativeGCMCipher location: class CustomSharedPrefsBackedKeyChain Main.java:107: error: cannot find symbol if(length == NativeGCMCipher.KEY_LENGTH) ^ symbol: variable NativeGCMCipher location: class CustomSharedPrefsBackedKeyChain Main.java:114: error: package SharedPreferences does not exist SharedPreferences.Editor editor = mSharedPreferences.edit(); ^ Main.java:120: error: cannot find symbol Log.d(log, key.toString()); ^ symbol: variable Log location: class CustomSharedPrefsBackedKeyChain Main.java:133: error: cannot find symbol Log.d(log, keyString.toString()); ^ symbol: variable Log location: class CustomSharedPrefsBackedKeyChain Main.java:134: error: cannot find symbol return Base64.decode(keyString, Base64.DEFAULT); ^ symbol: variable Base64 location: class CustomSharedPrefsBackedKeyChain Main.java:134: error: cannot find symbol return Base64.decode(keyString, Base64.DEFAULT); ^ symbol: variable Base64 location: class CustomSharedPrefsBackedKeyChain Main.java:145: error: cannot find symbol return Base64.encodeToString(key, Base64.DEFAULT); ^ symbol: variable Base64 location: class CustomSharedPrefsBackedKeyChain Main.java:145: error: cannot find symbol return Base64.encodeToString(key, Base64.DEFAULT); ^ symbol: variable Base64 location: class CustomSharedPrefsBackedKeyChain 39 errors
Standard output is empty