本文整理汇总了Java中com.facebook.crypto.Entity.create方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.create方法的具体用法?Java Entity.create怎么用?Java Entity.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.facebook.crypto.Entity
的用法示例。
在下文中一共展示了Entity.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public ConcealCrypto create(){
if (this.context == null){
throw new RuntimeException("Context cannot be null");
}
mEntityPassword = Entity.create(CipherUtils.obscureEncodeSixFourString(mEntityPasswordRaw.getBytes()));
makeKeyChain = new SharedPrefsBackedKeyChain(this.context.get(),(mKeyChain==null)?CryptoConfig.KEY_256:mKeyChain);
if (mKeyChain == null) {
crypto = AndroidConceal.get().createDefaultCrypto(makeKeyChain);
} else if (mKeyChain == CryptoConfig.KEY_128) {
crypto = AndroidConceal.get().createCrypto128Bits(makeKeyChain);
} else {
crypto = AndroidConceal.get().createCrypto256Bits(makeKeyChain);
}
return new ConcealCrypto(this);
}
示例2: encrypt
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
@Override
public String encrypt(String data) {
long startTime = System.currentTimeMillis();
ESLog.v("%s=>encrypt(%s)", getClass().getSimpleName(), data);
try {
Entity entity = Entity.create(getEntityName());
byte[] encrypted = crypto.encrypt(data.getBytes(SSCharset.CHARSET), entity);
ESLog.v("Encryption millis time: %d", System.currentTimeMillis() - startTime);
return encoding.toBase64(encrypted);
} catch (Exception e) {
ESLog.wtf("Something went wrong %s", e.getCause());
throw new UnexpectedEncryptionException(e);
}
}
示例3: decrypt
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
@Override
public String decrypt(String data) {
long startTime = System.currentTimeMillis();
ESLog.v("%s=>decrypt(%s)", getClass().getSimpleName(), data);
try {
Entity entity = Entity.create(getEntityName());
byte[] decodedData = encoding.fromBase64ToBytes(data);
byte[] decrypted = crypto.decrypt(decodedData, entity);
ESLog.v("Decryption millis time: %d", System.currentTimeMillis() - startTime);
return new String(decrypted);
} catch (Exception e) {
ESLog.wtf("Something went wrong %s", e.getCause());
throw new UnexpectedDecryptionException(e);
}
}
示例4: get
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public <T> T get(@NonNull String key, Type type) {
T value = null;
try {
String hashKey = CommonCrypto.hashPrefKey(key);
String old = mPreference.getString(hashKey, null);
if (old != null) {
Entity entity = Entity.create(key);
byte[] data = mCrypto.decrypt(Base64.decode(old, Base64.NO_WRAP), entity);
value = mGson.fromJson(new String(data, CharsetsSupport.UTF_8), type);
}
} catch (Exception e) {
Timber.w(e);
return null;
}
return value;
}
示例5: ConcealStringSetPreference
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public ConcealStringSetPreference(
final Crypto crypto,
final SharedPreferences preferences,
final String key,
final Set<String> defaultValue) {
super(preferences, key, defaultValue);
this.crypto = crypto;
this.entity = Entity.create(key);
}
示例6: ConcealStringPreference
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public ConcealStringPreference(
final Crypto crypto,
final SharedPreferences preferences,
final String key,
final String defaultValue) {
super(preferences, key, defaultValue);
this.crypto = crypto;
this.entity = Entity.create(key);
}
示例7: build
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public SharedPreferences build() {
if(!isInit) {
Log.w(TAG, "You need call 'SecurePreferences.init()' in onCreate() from your application class.");
}
KeyChain keyChain = new SharedPrefsBackedKeyChain(context, CryptoConfig.KEY_256);
Entity entity = Entity.create(
TextUtils.isEmpty(password) ? getClass().getPackage().getName() : password
);
return new SecurePreferences(
context,
keyChain,
entity,
sharedPrefFilename
);
}
示例8: decrypt
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public String decrypt(String key, String value, Type type) throws CryptoException {
try {
Entity entity = Entity.create(key);
byte[] data = mFbCrypto.decrypt(Base64.decode(value, Base64.NO_WRAP), entity);
return mGson.fromJson(new String(data, CharsetsSupport.UTF_8), type);
} catch (Exception e) {
throw new CryptoException(e);
}
}
示例9: decrypt
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
@Override
public String decrypt(String key, String value) throws Exception {
Entity entity = Entity.create(key);
byte[] decodedBytes = Base64.decode(value, Base64.NO_WRAP);
byte[] bytes = crypto.decrypt(decodedBytes, entity);
return new String(bytes);
}
示例10: put
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
private void put(String key, String hashKey, String value)
throws KeyChainException, CryptoInitializationException, IOException {
Entity entity = Entity.create(key); // original key
byte[] data = mCrypto.encrypt(value.getBytes(CharsetsSupport.UTF_8), entity);
mPreference.edit().putString(hashKey, Base64.encodeToString(data, Base64.NO_WRAP)).apply();
}
示例11: testConceal
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
@Test public void testConceal() throws Exception {
Entity entity = Entity.create("key");
String value = "value";
byte[] encryptedValue = crypto.encrypt(value.getBytes(), entity);
assertThat(encryptedValue).isNotNull();
String decryptedValue = new String(crypto.decrypt(encryptedValue, entity));
assertThat(decryptedValue).isEqualTo("value");
}
示例12: setEntityPassword
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
public void setEntityPassword(String password) {
if (password!=null)this.mEntityPassword = Entity.create(CipherUtils.obscureEncodeSixFourString(password.getBytes()));
}
示例13: encrypt
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
@Override
public String encrypt(String key, String value) throws Exception {
Entity entity = Entity.create(key);
byte[] bytes = crypto.encrypt(value.getBytes(), entity);
return Base64.encodeToString(bytes, Base64.NO_WRAP);
}
示例14: createUsernameEntity
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
private Entity createUsernameEntity(String service) {
String prefix = getEntityPrefix(service);
return Entity.create(prefix + "user");
}
示例15: createPasswordEntity
import com.facebook.crypto.Entity; //导入方法依赖的package包/类
private Entity createPasswordEntity(String service) {
String prefix = getEntityPrefix(service);
return Entity.create(prefix + "pass");
}