Java 类com.facebook.crypto.exception.CryptoInitializationException 实例源码

项目:Patrons    文件:ConcealStringSetPreference.java   
@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();
}
项目:Patrons    文件:ConcealStringPreference.java   
@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());
  }
}
项目:encryptedprefs    文件:MemoryKeyChain.java   
@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;
}
项目:secure-preferences    文件:SecurePreferences.java   
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;
}
项目:secure-preferences    文件:SecurePreferences.java   
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;
}
项目:secure-preferences    文件:SecurePreferences.java   
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;
}
项目:secure-preferences    文件:SecurePreferences.java   
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;
}
项目:ConcealSharedPreference-Android    文件:ConcealCrypto.java   
@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;
    }
}
项目:LsPush    文件:PreferenceUtils.java   
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();
}
项目:DroidCon-Poland    文件:CryptoManager.java   
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;
}
项目:droid-stealth    文件:ConcealCrypto.java   
/**
 * 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);
}
项目:droid-stealth    文件:ConcealCrypto.java   
/**
 * 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);
}
项目:ConcealSharedPreference-Android    文件:ConcealCrypto.java   
@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;
}
项目:Sunazuri    文件:EncryptionUtils.java   
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);
}
项目:Sunazuri    文件:EncryptionUtils.java   
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);
}
项目:DroidCon-Poland    文件:CryptoManager.java   
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();
}
项目:droid-stealth    文件:ICrypto.java   
/**
 * 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;
项目:droid-stealth    文件:ICrypto.java   
public void decrypt(File encrypted, File unencrypted, String entityName) throws IOException, CryptoInitializationException, KeyChainException;