开源加密解密库

OpenSSL

https://www.openssl.org/

https://wolfssl.com/wolfSSL/wolfssl-openssl.html?gclid=CI-H_fSCrssCFQVwvAodOOgDRg

C语言实现,整个软件包大概可以分成三个主要的功能部分:密码算法库、SSL协议库以及应用程序。OpenSSL的目录结构自然也是围绕这三个功能部分进行规划的。   作为一个基于密码学的安全开发包,OpenSSL提供的功能相当强大和全面,囊括了主要的密码算法、常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用。代码量比较庞大,使用起来不是很方便。支持跨平台。

 

crypto++

https://www.cryptopp.com/

https://sourceforge.net/projects/cryptopp/

C++语言实现,代码庞大且复杂, 使用起来不方便。支持跨平台。

 

CyaSSL

https://github.com/cyassl/cyassl

CyaSSL 软件包是一个快速的、具有双协议实现的 SSL ,主要适用嵌入式的设备。它包含一个 SSL 的客户端和服务器端的实现,支持兼容 OpenSSL 的多个 API 方法,支持 TLS 1.1 以及 AES, 3DES, RC4, HC-128, and RABBIT 等加密方法

C语言实现,该软件包是一个快速的、具有双协议实现的 SSL ,主要适用嵌入式的设备。它包含一个 SSL 的客户端和服务器端的时间,支持兼容 OpenSSL 的多个 API 方法,支持 TLS 1.1 以及 AES, 3DES, RC4, HC-128, and RABBIT 等加密方法。

http://baike.baidu.com/view/9329764.htm

https://segmentfault.com/a/1190000000471532

 

jsCrypto和Crypto-JS和pidCrypt

java script实现的加密解密库。jsCrypto 是一个实现了一些常用加密方法的 JavaScript 库,支持的算法包括:AES, SHA-1, HMAC, BASE64, RSA, ECC and IBE,这个库也可以在 ActionScript 下使用。Crypto-JS 为 JavaScript 提供了各种各样的加密算法,目前已支持的算法包括:MD5,SHA-1,SHA-256,AES,Rabbit,MARC4,HMAC 。

pidCrypt 是 JavaScript 的一个模块化的加密库,支持: AES (CBC & CTR Mode), RSA, MD5, SHA-1, SHA-256, SHA-384, SHA-512, ASN.1, Base64, UTF-8. The AES-CBC mode is compatible to OpenSSL.

 

xyssl

C语言实现,使用方便简单。实现了常用的大部分加密解密算法。下载地址为 :http://xyssl.sourcearchive.com/downloads/0.9/xyssl_0.9.orig.tar.gz

https://www.openhub.net/p/xyssl

[UPDATE 2008-12-31] As of now, XySSL is no longer maintained by Christophe Devine. The current project manager is Paul Bakker, and the new site can be accessed at: http://polarssl.org/

XySSL is an open-source cryptographic library for embedded systems. It provides standard crypto block: AES, SHA-1, X.509, etc. as well as higher lever protocols: SSL v3 and TLS v1. XySSL has been ported on a number of architectures, including ARM, PowerPC, MIPS, and Motorola 68000. Its already small memory footprint can be easily reduced to 50k for a basic SSL client or server, by modifying a single .h configuration file. XySSL is currently used in several open-source (GPL) and closed-source projects, such as Adobe's flash player.

 

 Bouncy Castle

Bouncy Castle 是一种用于Java平台的开放源码的轻量级密码术包。它支持大量的密码术算法,并提供 JCE 1.2.1 的实现。Bouncy Castle是轻量级的,从J2SE 1.4到J2ME(包括MIDP)平台,它都可以运行。它是在MIDP上运行的唯一完整的密码术包。

https://bouncycastle.org/

Welcome to the home of the Legion of the Bouncy Castle. A fun place to stay, if you've got some time to kill.

The Legion of the Bouncy Castle

Here at the Bouncy Castle, we believe in encryption. That's something that's near and dear to our hearts. We believe so strongly in encryption, that we've gone to the effort to provide some for everybody, and we've now been doing it for over 15 years!

The Bouncy Castle Crypto APIs are looked after by an Australian Charity, the Legion of the Bouncy Castle Inc., which looks after the care and feeding of the Bouncy Castle APIs. If you would like to help support this effort please see our donations page or purchase a support contract through Crypto Workshop. Requests to sponsor specific work on the APIs are also most welcome.

The Bouncy Castle APIs currently consist of the following:

 

SpongyCastle

Spongy Castle SpongyCastle 对最新版本的 BouncyCastle 进行了简单地重新打包。

所有包名已经从 org.bouncycastle* 该至 * org.spongycastle - 。以避免类加载器冲突。

Java Security API Provider 的名字改成 SC

类名没有 改版,所以 BouncyCastleProvider 类仍是 Bouncy ,而非 Spongy,但转移到 org.spongycastle.jce.provider 包

https://github.com/rtyley/spongycastle

https://rtyley.github.io/spongycastle/

Why?

The Android platform unfortunately ships with a cut-down version of Bouncy Castle - as well as being crippled, it also makes installing an updated version of the libraries difficult due to classloader conflicts.

Spongy Castle is the stock Bouncy Castle libraries with a couple of small changes to make it work on Android:

  • all package names have been moved from org.bouncycastle.* to org.spongycastle.* - to avoid classloader conflicts
  • the Java Security API Provider name is now SC rather than BC
  • no class names change, so the BouncyCastleProvider class remains Bouncy, not Spongy, but moves to the org.spongycastle.jce.provider package.

Download

Spongy Castle artifacts are published on Maven Central. Use Gradle or the android-maven-plugin to make the most of this, or click the jar links below - make sure you include all dependencies:

 

数据加密包 Conceal

Conceal 是 Facebook 推出的一个用来对数据进行快速加密和认证的开发包,应用可以使用它来加密数据和大文件存储。Conceal 和其他加密软件不同的是它提供了 Smorgasbord 加密算法和选项,这不是一个一般意义上的数据加密包,只是提供一些有用的方法。

https://facebook.github.io/conceal/

示例代码:

// Creates a new Crypto object with default implementations of 
// a key chain as well as native library.
Crypto crypto = new Crypto(
  new SharedPrefsBackedKeyChain(context),
  new SystemNativeCryptoLibrary());

FileOutputStream fileStream = new FileOutputStream(file);

// Creates an output stream which encrypts the data as
// it is written to it and writes it out to the file.
OutputStream outputStream = crypto.getCipherOutputStream(
  fileStream,
  entity);

// Write plaintext to it.
outputStream.write(plainText);
outputStream.close();

android-crypt-helper

为防止网络传输过程中重要数据被篡改,客户端与服务端都会对发出的数据签名或加密,对收到的数据验签或解密。签名可能用到MD5,SHA1,加解密可能用到3DES,AES,RSA等。加密数据传输一般以字符串形式,通常会用到BASE64,HEX转换工具。

一、JAVA方式
笔者搜集了上面提到的主要几种加解密方式及转换的实现,在此分享出来供大家参考,欢迎提意见,我会进一步完善~

二、JNI封装算法
以上方式为JAVA实现,为了增加代码反编译的难度,大家还可以尝试将算法及KEY封装在JNI中,可参考:

GitHub地址:https://github.com/panxw/android-jni-project.git

三、使用说明
Test.java:总测试程序。
AESHelper.java:AES加解密工具。
DESedeHelper.java:3DES加解密工具。
RSAHelper.java:RSA加解密工具。
SignatureHelper.java:MD5, SHA-1签名工具。
Base64.java及Hex.java:字符串与字节码转换工具。
Base64如报错,请用security中的jar文件换掉JRE/lib/security中的jar包。

 

Java的NTRU加密算法库 NTRU

NTRU 加密系统提供了 NTRUEncrypt 和 NTRUSigh 算法的实现。

https://en.wikipedia.org/wiki/NTRU

http://tbuktu.github.io/ntru/

https://github.com/tbuktu/ntru

下图是与其他加密系统的性能比较:

Maven 中使用的方法:

  <dependency>
    <groupId>net.sf.ntru</groupId>
    <artifactId>ntru</artifactId>
    <version>1.2</version>
  </dependency>

 

加解密工具 jBCrypt

http://www.mindrot.org/projects/jBCrypt/

https://github.com/jeremyh/jBCrypt

java版Bcrypt ,加解密工具 (用于账号密码加密,被时间检证过了) ,对用户的口令进行Hash,并使用salt,以防止Rainbow 攻击(Hash算法可用MD5或SHA1等,对口令使用salt的意思是,user 在设定密码时,system 产生另外一个random string(salt)。在datbase 存的是与salt + passwd 产的md5sum 及salt。 当要验证密码时就把user 输入的string 加上使用者的salt,产生md5sum 来比对。 理论上用salt 可以大幅度让密码更难破解,相同的密码除非刚好salt 相同,最后存在database 上的内容是不一样的。使用慢一点的Hash算法来保存口令,如 bcrypt (被时间检证过了) 或是 scrypt (更强,但是也更新一些)

The API is very simple:

// Hash a password for the first time

String hashed = BCrypt.hashpw(password, BCrypt.gensalt());

// gensalt's log_rounds parameter determines the complexity

// the work factor is 2**log_rounds, and the default is 10

String hashed = BCrypt.hashpw(password, BCrypt.gensalt(12));

// Check that an unencrypted password matches one that has

// previously been hashed

if (BCrypt.checkpw(candidate, hashed))

System.out.println("It matches");

else

System.out.println("It does not match");

 

Spring Crypto Utils

http://springcryptoutils.com/

http://mvnrepository.com/artifact/com.google.code.spring-crypto-utils/spring-crypto-utils/1.3.0

https://github.com/mcaserta/spring-crypto-utils

Spring Crypto Utils 旨在提供纯 Java 的加密 API,用来简化公私钥和证书存储、对称和非对称加密方法的封装,可方便的跟 Spring 框架进行集成。

 

Java加密包 Jasypt

http://www.jasypt.org/

http://mvnrepository.com/artifact/org.jasypt

Jasypt这个Java类包为开发人员提供一种简单的方式来为项目增加加密功能,包括:密码Digest认证,文本和对象加密,集成 hibernate,Spring Security(Acegi)来增强密码管理。Jasypt开发团队推出了Java加密工具Jasypt 1.4,它可与Spring Framework、Hibernate和Acegi Security集成。

与项目有关的一位开发者表示,Jasypt是一个Java库,可以使开发者不需太多操作来给Java项目添加基本加密功能,而且不需要知道加密原理。

Jasypt也即Java Simplified Encryption是Sourceforge.net上的一个开源项目。在当地时间11月23号的通告中,Jasypt 1.4的新特征包括:加密属性文件(encryptable properties files)、Spring Framework集成、加密Hibernate数据源配置、新的命令行工具、URL加密的Apache wicket集成以及升级文档。

根据Jasypt文档,该技术可用于加密任务与应用程序,例如加密密码、敏感信息和数据通信、创建完整检查数据的sums. 其他性能包括高安全性、基于标准的加密技术、可同时单向和双向加密的加密密码、文本、数字和二进制文件。Jasypt也可以与Acegi Security整合也即Spring Security。Jasypt亦拥有加密应用配置的集成功能,而且提供一个开放的API从而任何一个Java Cryptography Extension都可以使用Jasypt。

Jasypt还符合RSA标准的基于密码的加密,并提供了无配置加密工具以及新的、高可配置标准的加密工具。

发表评论