当前位置: 首页>>代码示例>>Java>>正文


Java CryptoOutputStream类代码示例

本文整理汇总了Java中org.apache.commons.crypto.stream.CryptoOutputStream的典型用法代码示例。如果您正苦于以下问题:Java CryptoOutputStream类的具体用法?Java CryptoOutputStream怎么用?Java CryptoOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CryptoOutputStream类属于org.apache.commons.crypto.stream包,在下文中一共展示了CryptoOutputStream类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.commons.crypto.stream.CryptoOutputStream; //导入依赖的package包/类
public static void main(String []args) throws IOException {
    final SecretKeySpec key = new SecretKeySpec(getUTF8Bytes("1234567890123456"),"AES");
    final IvParameterSpec iv = new IvParameterSpec(getUTF8Bytes("1234567890123456"));
    Properties properties = new Properties();
    final String transform = "AES/CBC/PKCS5Padding";

    String input = "hello world!";
    //Encryption with CryptoOutputStream.

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    try (CryptoOutputStream cos = new CryptoOutputStream(transform, properties, outputStream, key, iv)) {
        cos.write(getUTF8Bytes(input));
        cos.flush();
    }

    // The encrypted data:
    System.out.println("Encrypted: "+Arrays.toString(outputStream.toByteArray()));

    // Decryption with CryptoInputStream.
    InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());

    try (CryptoInputStream cis = new CryptoInputStream(transform, properties, inputStream, key, iv)) {
        byte[] decryptedData = new byte[1024];
        int decryptedLen = 0;
        int i;
        while ((i = cis.read(decryptedData, decryptedLen, decryptedData.length - decryptedLen)) > -1) {
            decryptedLen += i;
        }
        System.out.println("Decrypted: "+new String(decryptedData, 0, decryptedLen, StandardCharsets.UTF_8));
    }
}
 
开发者ID:apache,项目名称:commons-crypto,代码行数:33,代码来源:StreamExample.java

示例2: createEncryptionStream

import org.apache.commons.crypto.stream.CryptoOutputStream; //导入依赖的package包/类
@Override
public OutputStream createEncryptionStream(OutputStream out) {
  if (!initialized) {
    reset();
  }
  try {
    return new CryptoOutputStream(cipherMode, properties, out, key,  new
        IvParameterSpec(iv));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:13,代码来源:CommonsCryptoAESEncryptor.java

示例3: getCryptOut

import org.apache.commons.crypto.stream.CryptoOutputStream; //导入依赖的package包/类
public OutputStream getCryptOut(final OutputStream out, final KeyIv keyIv)
    throws IOException {
    return new CryptoOutputStream(TRANSFORM, new Properties(), out,
        new SecretKeySpec(keyIv.getKey(), "AES"), new IvParameterSpec(keyIv.getIv()));
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:6,代码来源:Cryptor.java


注:本文中的org.apache.commons.crypto.stream.CryptoOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。