Java、Android(安卓)加密解密工具类,不依赖于其他库。
需要先在project的build.gradle下添加:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.whvcse:EndecryptUtil:1.0.4'
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>EndecryptUtil</artifactId>
<version>1.0.4</version>
</dependency>
String str = "Hello Word!";
String rs = EndecryptUtils.encrytBase64(str);
String str = "SGVsbG8gV29yZCE=";
String rs = EndecryptUtils.decryptBase64(str);
String str = "Hello Word!";
String rs = EndecryptUtils.encrytHex(str);
String str = "48656c6c6f20576f726421";
String rs = EndecryptUtils.decryptHex(str);
String str = "Hello Word!";
Key key = EndecryptUtils.generateKey("wangfan");
String rs = EndecryptUtils.encrytAes(str, key);
String str = "2c700dadcc66726f1665a4d604f6e6a4f8a498bc0173ed5f49f063b8f1a74f7e";
Key key = EndecryptUtils.generateKey("wangfan");
String rs = EndecryptUtils.decryptAes(str, key);
String str = "Hello Word!";
String rs = EndecryptUtils.encrytMd5(str);
String str = "Hello Word!";
String salt = "wangfan"; //盐
int hashIterations = 3; //散列次数,把密文再进行3次Md5加密
String rs = EndecryptUtils.encrytMd5(str, salt, hashIterations);