本文整理汇总了Java中com.facebook.crypto.Entity类的典型用法代码示例。如果您正苦于以下问题:Java Entity类的具体用法?Java Entity怎么用?Java Entity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Entity类属于com.facebook.crypto包,在下文中一共展示了Entity类的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: encrypt
import com.facebook.crypto.Entity; //导入依赖的package包/类
@Override
public EncryptionResult encrypt(@NonNull String service, @NonNull String username, @NonNull String password) throws CryptoFailedException {
if (!crypto.isAvailable()) {
throw new CryptoFailedException("Crypto is missing");
}
Entity usernameEntity = createUsernameEntity(service);
Entity passwordEntity = createPasswordEntity(service);
try {
byte[] encryptedUsername = crypto.encrypt(username.getBytes(Charset.forName("UTF-8")), usernameEntity);
byte[] encryptedPassword = crypto.encrypt(password.getBytes(Charset.forName("UTF-8")), passwordEntity);
return new EncryptionResult(encryptedUsername, encryptedPassword, this);
} catch (Exception e) {
throw new CryptoFailedException("Encryption failed for service " + service, e);
}
}
示例6: decrypt
import com.facebook.crypto.Entity; //导入依赖的package包/类
@Override
public DecryptionResult decrypt(@NonNull String service, @NonNull byte[] username, @NonNull byte[] password) throws CryptoFailedException {
if (!crypto.isAvailable()) {
throw new CryptoFailedException("Crypto is missing");
}
Entity usernameEntity = createUsernameEntity(service);
Entity passwordEntity = createPasswordEntity(service);
try {
byte[] decryptedUsername = crypto.decrypt(username, usernameEntity);
byte[] decryptedPassword = crypto.decrypt(password, passwordEntity);
return new DecryptionResult(
new String(decryptedUsername, Charset.forName("UTF-8")),
new String(decryptedPassword, Charset.forName("UTF-8")));
} catch (Exception e) {
throw new CryptoFailedException("Decryption failed for service " + service, e);
}
}
示例7: 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);
}
示例8: 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);
}
示例9: 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
);
}
示例10: SecurePreferences
import com.facebook.crypto.Entity; //导入依赖的package包/类
private SecurePreferences(Context context,
final KeyChain keyChain,
final Entity entity,
final String sharedPrefFilename) {
this.entity = entity;
this.sharedPreferences = getSharedPreferenceFile(context, sharedPrefFilename);
this.crypto = AndroidConceal.get().createCrypto256Bits(keyChain);
}
示例11: 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);
}
}
示例12: 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);
}
示例13: 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();
}
示例14: CryptoManager
import com.facebook.crypto.Entity; //导入依赖的package包/类
public CryptoManager(Context context, String path, String password) {
this.path = path;
this.crypto = new Crypto(
new SharedPrefsBackedKeyChain(context),
new SystemNativeCryptoLibrary());
entity = new Entity(password);
checkPathExists();
}
示例15: 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");
}