微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Apache Commons Crypto

程序名称:Apache Commons Crypto

授权协议: Apache

操作系统: 跨平台

开发语言: Java

Apache Commons Crypto 介绍

Apache Commons Crypto 是一个加密库,使用 AES-NI (Advanced Encryption Standard New
Instructions) 进行优化。提供了加密级别和流级别的 API。开发者可以使用最少代码来实现高性能的 AES 加解密应用。

Maven:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-crypto</artifactId>
    <version>1.0.0</version>
</dependency>

示例代码

Properties properties = new Properties();
//Creates a CryptoCipher instance with the transformation and properties.
CryptoCipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_nopADDING, properties);

String input = "hello world!";
int inputOffset = 0;
int inputLen = input.length();
byte[] output = new byte[1024];
int outputOffset = 0;
//Initializes the cipher with ENCRYPT_MODE, key and iv.
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key,"AES"), new IvParameterSpec(iv));
//Continues a multiple-part encryption/decryption operation for byte array.
cipher.update(input.getBytes("UTF-8"), inputOffset, inputLen, output, outputOffset);
//We should call do final at the end of encryption/decryption.
cipher.doFinal(inBuffer, outBuffer);
//Closes the cipher.
cipher.close();

Apache Commons Crypto 官网

http://commons.apache.org/proper/commons-crypto/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐