本文整理匯總了Java中org.spongycastle.crypto.io.CipherOutputStream類的典型用法代碼示例。如果您正苦於以下問題:Java CipherOutputStream類的具體用法?Java CipherOutputStream怎麽用?Java CipherOutputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CipherOutputStream類屬於org.spongycastle.crypto.io包,在下文中一共展示了CipherOutputStream類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeAndRead
import org.spongycastle.crypto.io.CipherOutputStream; //導入依賴的package包/類
private byte[] writeAndRead(byte[] data, byte[] key) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CipherOutputStream outStream = IoUtil.encryptTo(baos, key);
outStream.write(data);
outStream.close();
byte[] cipherText = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(cipherText);
CipherInputStream inStream = IoUtil.decryptFrom(bais, key);
byte[] result = ByteStreams.toByteArray(inStream);
inStream.close();
return result;
}
示例2: encryptTo
import org.spongycastle.crypto.io.CipherOutputStream; //導入依賴的package包/類
static CipherOutputStream encryptTo(OutputStream stream, byte[] key) throws IOException {
byte[] randomIv = new byte[BLOCK_SIZE];
RANDOM.nextBytes(randomIv);
stream.write(randomIv);
return new CipherOutputStream(
stream,
createAes128CtrPkcs7PaddingCipher(true, randomIv, key));
}
示例3: upsertCredential
import org.spongycastle.crypto.io.CipherOutputStream; //導入依賴的package包/類
/**
* Writes (or overwrites) the provided credential to the store. Requires that the credential
* store is unlocked. May be empty.
* @throws IOException if the credential could not be written.
*/
public void upsertCredential(Credential credential) throws IOException {
checkUnlocked();
initAuthDomainDir(credential.getAuthDomain().getUri());
File credentialFile = getCredentialFile(credential);
CipherOutputStream cipherOutputStream = IoUtil.encryptTo(credentialFile, mKey);
try {
credential.writeTo(cipherOutputStream);
} finally {
IoUtil.closeQuietly(cipherOutputStream, LOG_TAG);
}
upsertHint(credential);
}
示例4: generateKeyTestFile
import org.spongycastle.crypto.io.CipherOutputStream; //導入依賴的package包/類
private void generateKeyTestFile() throws IOException {
CipherOutputStream stream = null;
try {
stream = IoUtil.encryptTo(getKeyTestFile(), mKey);
stream.write(KEY_VERIFICATION_BYTES);
} finally {
IoUtil.closeQuietly(stream, LOG_TAG);
}
}
示例5: getEncryptedOutputStream
import org.spongycastle.crypto.io.CipherOutputStream; //導入依賴的package包/類
/**
* Create an encrypted output stream from an unencrypted output stream
*/
public static OutputStream getEncryptedOutputStream (OutputStream decryptedOutputStream, byte[] keyData, byte[] ivData) {
final ParametersWithIV keyAndIV = new ParametersWithIV(new KeyParameter(keyData), ivData);
PaddedBufferedBlockCipher pbbc = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
pbbc.init(true, keyAndIV);
return new CipherOutputStream(decryptedOutputStream, pbbc);
}