cloudopt-plugin-encrypt 是 Cloudopt Next 的加密工具包。目前支持 Base64、MD5、AES、RSA、DES、Sha1、Sha 加密算法。

在使用前请先自行引用相应的依赖,请自行添加版本号。

  1. <dependency>
  2. <groupId>net.cloudopt.next</groupId>
  3. <artifactId>cloudopt-next-encrypt</artifactId>
  4. </dependency>

Base64

  1. var e = Base64Encrypt()
  2. var s = e.encrypt("hello")
  3. println(s)
  4. println(e.decrypt(s))
  1. Encrypt e = new Base64Encrypt();
  2. String s = e.encrypt("hello");
  3. System.out.println(s);
  4. System.out.println(e.decrypt(s));

MD5

  1. var e = MD5Encrypt()
  2. var s = e.encrypt("hello")
  3. println(s)
  1. Encrypt e = new MD5Encrypt();
  2. String s = e.encrypt("hello");
  3. System.out.println(s);

AES

  1. var e = AesEncrypt()
  2. var s = e.setPassword("lKY7YO6jqRnzNOJ3").encrypt("hello")
  3. println(s)
  4. println(e.decrypt(s))
  1. Encrypt e = new AesEncrypt();
  2. String s = e.setPassword("lKY7YO6jqRnzNOJ3").encrypt("hello");
  3. System.out.println(s);
  4. System.out.println(e.decrypt(s));

RSA

  1. var publicK = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCFmf/HWpTZ9smPjyM6SUa0UvUQGfIY+OMV5S8zNqmwz11pYovtz57okRZreK8RtBkBOcOKyk7KRMm0agMm0qBaz0ESuFJmIbl3pEn3l/m0aCNnFv2ehijXl6AoW3bB/fKFoKUcRGXet4R/ka1qcxUJaH3uZtmiyPn8G66BhZXBbQIDAQAB"
  2. var privateK = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAIWZ/8dalNn2yY+PIzpJRrRS9RAZ8hj44xXlLzM2qbDPXWlii+3PnuiRFmt4rxG0GQE5w4rKTspEybRqAybSoFrPQRK4UmYhuXekSfeX+bRoI2cW/Z6GKNeXoChbdsH98oWgpRxEZd63hH+RrWpzFQlofe5m2aLI+fwbroGFlcFtAgMBAAECgYAZMloS9vprwSdyc8RpEbjL+XlOeBY4r3fkgTzNo9mNBw7O+U76otWNdw+LZU9fP2AX4xUF7/G8JA0GgZfmkoK7VTbpBpX7BeW664GzVa9sDFsf2WMD01J9mndcHjcyyeuwBSXliJupjDAxpDTWcd6U2gMgv0SsTxCZQo2Wdr0y4QJBAPP/OY4Mc68P2bwBXyJcnKZYC0sSgeudZ8URXNbNtEgiklO5SV5hteEBfHYjCzbLf7zE38pMNVtuNua2paNM1kcCQQCMLIKO3wRDQgo/LZxy58kjknAVbZJypZj6Yz8O8poIB2sUyyBPNVOXLg4eOSBMQXH2yJNIw4kv+KAxA+8D2GCrAkEAwHV7Ao7T2SxZhLBYSBRhA9zC2653iFAagBlX759GKvgKD7xBIQ9VlWvErrKpr8kIsu9fzoQaOkpPR+Cd+pcrFQJAfrfmNx5pjhvvg3nKSx46+UtyxAxQLhCCISkDYpHyqXt7VErlJHYC4VKjNLNT/VvUmNJuQ4NxS8qplmYF9yXvDQJAO/GlhZ+qmCOpfKb/pOHRUYSZsPZ0/85sQDQ2u/GYp4jtDqeYNoqZt0Oqr9bEJkJ2sRZnoRGXUePuR7kMoejy9w=="
  3. var e = RsaEncrypt()
  4. e.setPublicKey(publicK).setPrivateKey(privateK)
  5. var s = e.encrypt("hello")
  6. println(s)
  7. println(e.decrypt(s))
  1. Encrypt e = new RsaEncrypt();
  2. e.setPublicKey(publicK).setPrivateKey(privateK);
  3. String s = e.encrypt("hello");
  4. System.out.println(s);
  5. System.out.println(e.decrypt(s));

DES

  1. var e = DesEncrypt().setPassword("12345678")
  2. var s = e.encrypt("hello")
  3. println(s)
  4. println(e.decrypt(s))
  1. Encrypt e = new DesEncrypt().setPassword("12345678");
  2. String s = e.encrypt("hello");
  3. System.out.println(s);
  4. System.out.println(e.decrypt(s));

Sha1

  1. var e = SHA1Encrypt()
  2. var s = e.encrypt("hello")
  3. println(s)
  1. Encrypt e = new SHA1Encrypt();
  2. String s = e.encrypt("hello");
  3. System.out.println(s);

Sha

  1. var e = SHAEncrypt()
  2. var s = e.encrypt("hello")
  3. println(s)
  1. Encrypt e = new SHAEncrypt();
  2. String s = e.encrypt("hello");
  3. System.out.println(s);