Skip to content

Commit

Permalink
修改readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangpan committed May 4, 2023
1 parent 272717d commit 8f0782d
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,116 @@
```

### dv-commons-secure
- 支持常见加密方式,
- 支持RSA2|MD5|HMACSHA256签名
- 使用
```java
public void testGeneratorCode() throws NoSuchAlgorithmException {
KeyGenerator instance = KeyGenerator.getInstance("HmacSHA1");
instance.init(256, new SecureRandom());
SecretKey key = instance.generateKey();
System.out.println(Base64.getEncoder().encodeToString(key.getEncoded()));
System.out.println(SecureTimeUtil.generatorCode(System.currentTimeMillis() / 1000, 30, key, "HmacSHA1"));

SecretKeySpec secretKeySpec = new SecretKeySpec(key.getEncoded(), "HmacSHA1");
System.out.println(SecureTimeUtil.generatorCode(System.currentTimeMillis() / 1000, 30, secretKeySpec, "HmacSHA1"));

}

public void testGenerate() {

RsaGenerator generator = SecureUtil.rsa().generator(2048);
{
RsaKeyGenerator<String> rsaKeyGenerator = generator.base64();
System.out.println(rsaKeyGenerator.publicKey());
System.out.println(rsaKeyGenerator.privateKey());
}

{
RsaKeyGenerator<String> xml = generator.xml();
System.out.println(xml.publicKey());
System.out.println(xml.privateKey());
}

{
System.out.println("-------------------");
RsaKeyGenerator<byte[]> bytes = generator.bytes();
System.out.println(new String(bytes.publicKey(), StandardCharsets.UTF_8));
System.out.println("++++++++++++++++++++");
System.out.println(new String(bytes.privateKey(), StandardCharsets.UTF_8));
System.out.println("--------------------");
}

String strings = SecureUtil.rsa().base64Key(generator.base64().publicKey()).plaintext("这是个测试").base64Strings();
System.out.println(strings);
String strings1 = SecureUtil.rsa().base64Key(generator.base64().privateKey()).base64Ciphertext(strings).strings();
System.out.println(strings1);

}

public void testSecret(){
{
RsaGenerator generator = SecureUtil.rsa().generator(2048);
RsaKeyGenerator<String> keyGenerator = generator.base64();
String publicKey = keyGenerator.publicKey();
String privateKey = keyGenerator.privateKey();

System.out.printf("公钥:%s\n",publicKey);
System.out.printf("私钥:%s\n",privateKey);

String ciphertext = SecureUtil.rsa().base64Key(publicKey).plaintext("这是个测试").base64Strings();
System.out.printf("密文:%s\n", ciphertext);
String plaintext = SecureUtil.rsa().base64Key(privateKey).base64Ciphertext(ciphertext).strings();
System.out.printf("明文:%s\n", plaintext);
}

{
AesKeyGenerator generator = SecureUtil.aes().generator(256);
String s = generator.base64();
System.out.printf("秘钥:%s\n",s);
String ciphertext = SecureUtil.aes().base64Key(s).plaintext("这是个测试").base64Strings();
System.out.printf("密文:%s\n", ciphertext);
String plaintext = SecureUtil.aes().base64Key(s).base64Ciphertext(ciphertext).strings();
System.out.printf("明文:%s\n", plaintext);
}

}

public void testSign(){
{
String key = UUID.randomUUID().toString();
Map<String, String> signMap = SignUtils.signMap(new HashMap<String, String>() {{
this.put("test", "123");
}}, key, SignType.HMACSHA256);
System.out.println(signMap);
boolean valid = SignUtils.isValid(signMap, key);
System.out.println(valid);
}

{
String key = UUID.randomUUID().toString();
Map<String, String> signMap = SignUtils.signMap(new HashMap<String, String>() {{
this.put("test", "123");
}}, key, SignType.MD5);
System.out.println(signMap);
boolean valid = SignUtils.isValid(signMap, key);
System.out.println(valid);
}

{
RsaKeyGenerator<String> generator = SecureUtil.rsa().generator(2048).base64();
Map<String, String> signMap = SignUtils.signMap(new HashMap<String, String>() {{
this.put("test", "123");
}}, generator.privateKey(), SignType.RSA2);
System.out.println(signMap);
boolean valid = SignUtils.isValid(signMap, generator.publicKey());
System.out.println(valid);
}

}
```

### dv-commons-script
- 支持脚本类型为 `GlueTypeEnum` 中表述的
- bean或者groovy模式, 需要继承 `IHandler` 接口, bean模式
- 基础执行器为`BaseExecutor`继承`IExecutor`,如果需要自己重写基础执行器, 使用java原生spi机制即可
Expand Down

0 comments on commit 8f0782d

Please sign in to comment.