本文整理汇总了Java中com.facebook.crypto.exception.CryptoInitializationException类的典型用法代码示例。如果您正苦于以下问题:Java CryptoInitializationException类的具体用法?Java CryptoInitializationException怎么用?Java CryptoInitializationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CryptoInitializationException类属于com.facebook.crypto.exception包,在下文中一共展示了CryptoInitializationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
@Override public void set(final Set<String> value) {
final Set<String> encryptedSet = new HashSet<>(value.size());
for (final String s : value) {
try {
encryptedSet.add(Base64.encodeToString(
crypto.encrypt(
s.getBytes(Charset.defaultCharset()),
entity
),
Base64.NO_WRAP
));
} catch (KeyChainException | CryptoInitializationException | IOException e) {
Log.e(TAG, e.getMessage());
encryptedSet.add(null);
}
}
preferences.edit().putStringSet(key, encryptedSet).apply();
}
示例2: set
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
@Override public void set(final String value) {
try {
if (value != null) {
super.set(Base64.encodeToString(
crypto.encrypt(
value.getBytes(Charset.defaultCharset()),
entity
),
Base64.NO_WRAP
));
} else {
delete();
}
} catch (KeyChainException | CryptoInitializationException | IOException e) {
Log.e(TAG, e.getMessage());
}
}
示例3: getCipherKey
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
@Override
public synchronized byte[] getCipherKey() throws KeyChainException {
if (!setCipherKey) {
PasswordBasedKeyDerivation derivation = new PasswordBasedKeyDerivation(secureRandom, nativeCryptoLibrary);
derivation.setPassword(password);
derivation.setSalt(password.getBytes());
derivation.setIterations(ITERATION_COUNT);
derivation.setKeyLengthInBytes(cryptoConfig.keyLength);
try {
cipherKey = derivation.generate();
} catch (CryptoInitializationException e) {
return null;
}
}
setCipherKey = true;
return cipherKey;
}
示例4: encrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
private String encrypt(final String plainText) {
if (TextUtils.isEmpty(plainText)) {
return plainText;
}
byte[] cipherText = null;
if (!crypto.isAvailable()) {
log(Log.WARN, "encrypt: crypto not available");
return null;
}
try {
cipherText = crypto.encrypt(plainText.getBytes(), entity);
} catch (KeyChainException | CryptoInitializationException | IOException e) {
log(Log.ERROR, "encrypt: " + e);
}
return cipherText != null ? Base64.encodeToString(cipherText, Base64.DEFAULT) : null;
}
示例5: decrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
private String decrypt(final String encryptedText) {
if (TextUtils.isEmpty(encryptedText)) {
return encryptedText;
}
byte[] plainText = null;
if (!crypto.isAvailable()) {
log(Log.WARN, "decrypt: crypto not available");
return null;
}
try {
plainText = crypto.decrypt(Base64.decode(encryptedText, Base64.DEFAULT), entity);
} catch (KeyChainException | CryptoInitializationException | IOException e) {
log(Log.ERROR, "decrypt: " + e);
}
return plainText != null
? new String(plainText)
: null;
}
示例6: obscureFile
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
@RequiresPermission(allOf = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public File obscureFile(File file,boolean deleteOldFile){
if (enableCrypto) {
try {
boolean isImage = FileUtils.isFileForImage(file);
File mEncryptedFile = new File(makeDirectory()+DEFAULT_PREFIX_FILENAME+file.getName());
OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(mEncryptedFile));
OutputStream outputStream = crypto.getCipherOutputStream(fileStream, mEntityPassword);
int read;
byte[] buffer = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
while ((read = bis.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
outputStream.close();
bis.close();
if (deleteOldFile)
file.delete();
File pathDir = new File(isImage?makeImagesDirectory():makeFileDirectory());
return FileUtils.moveFile(mEncryptedFile,pathDir);
} catch (KeyChainException | CryptoInitializationException | IOException e) {
e.printStackTrace();
return null;
}
}
else {
return file;
}
}
示例7: put
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的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();
}
示例8: decryptPhoto
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
public Bitmap decryptPhoto(String filename) throws IOException, CryptoInitializationException, KeyChainException {
FileInputStream fileStream = new FileInputStream(path + filename);
InputStream inputStream = crypto.getCipherInputStream(fileStream, entity);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
inputStream.close();
return bitmap;
}
示例9: encrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
/**
* Encrypts the unencrypted file. Can throw a lot of errors
*
* @param encrypted
* @param unencrypted
* @param entityName
* @throws IOException
* @throws CryptoInitializationException
* @throws KeyChainException
*/
@Override
public void encrypt(File encrypted, File unencrypted,
String entityName) throws IOException, CryptoInitializationException, KeyChainException {
doFileChecks(unencrypted, encrypted);
FileInputStream from = new FileInputStream(unencrypted); // Stream to read from source
OutputStream to = crypto.getCipherOutputStream(new FileOutputStream(encrypted),
new Entity(entityName)); // Stream to write to destination
copyStreams(from, to);
}
示例10: decrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
/**
* Decrypts the encrypted file. Can also throw a lot of errors
*
* @param encrypted
* @param unencrypted
* @param entityName
* @throws IOException
* @throws CryptoInitializationException
* @throws KeyChainException
*/
@Override
public void decrypt(File encrypted, File unencrypted,
String entityName) throws IOException, CryptoInitializationException, KeyChainException {
doFileChecks(encrypted, unencrypted);
InputStream from = crypto.getCipherInputStream(new FileInputStream(encrypted),
new Entity(entityName));
FileOutputStream to = new FileOutputStream(unencrypted);
copyStreams(from, to);
}
示例11: deObscureFile
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
@RequiresPermission(allOf = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public File deObscureFile(File file,boolean deleteOldFile){
if (enableCrypto) {
try {
if (file.getName().contains(DEFAULT_PREFIX_FILENAME)) {
boolean isImage = FileUtils.isFileForImage(file);
File mDecryptedFile = new File(makeDirectory() + file.getName().replace(DEFAULT_PREFIX_FILENAME,""));
InputStream inputStream = crypto.getCipherInputStream(new FileInputStream(file), mEntityPassword);
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputStream outputStream = new FileOutputStream(mDecryptedFile);
BufferedInputStream bis = new BufferedInputStream(inputStream);
int mRead;
byte[] mBuffer = new byte[1024];
while ((mRead = bis.read(mBuffer)) != -1) {
outputStream.write(mBuffer, 0, mRead);
}
bis.close();
out.writeTo(outputStream);
inputStream.close();
outputStream.close();
out.close();
if (deleteOldFile)
file.delete();
File pathDir = new File(isImage?makeImagesDirectory():makeFileDirectory());
return FileUtils.moveFile(mDecryptedFile, pathDir);
}
return null;
} catch (KeyChainException | CryptoInitializationException | IOException e) {
e.printStackTrace();
return null;
}
}
return file;
}
示例12: encrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
public static String encrypt(Crypto crypto, String alias, String plainText)
throws IOException, KeyChainException, CryptoInitializationException {
final byte[] bytes = crypto.encrypt(plainText.getBytes(ENCODING), Entity.create(alias));
return Base64.encodeToString(bytes, BASE64_FLAG);
}
示例13: decrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
public static String decrypt(Crypto crypto, String alias, String encryptedText)
throws IOException, KeyChainException, CryptoInitializationException {
final byte[] bytes = crypto.decrypt(Base64.decode(encryptedText, BASE64_FLAG), Entity.create(alias));
return new String(bytes, ENCODING);
}
示例14: savePhotoEncrypted
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
public void savePhotoEncrypted(Bitmap imageBitmap, String filename) throws KeyChainException, CryptoInitializationException, IOException {
FileOutputStream fileStream = new FileOutputStream(path + filename);
OutputStream outputStream = crypto.getCipherOutputStream(fileStream, entity);
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
}
示例15: encrypt
import com.facebook.crypto.exception.CryptoInitializationException; //导入依赖的package包/类
/**
* Encrypts a file input stream to the given file
* @param encrypted file to be written to. Cannot be a directory
* @param unencrypted the original file to be encrypted
* @exception java.io.IOException thrown when the operation fails, either because the encrypted
* file already exists, or something failed during encryption
*/
public void encrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException;