@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.CharsetUtil ;
import cn.hutool.core.util.CharsetUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.crypto.SecureUtil ;
import cn.hutool.crypto.SecureUtil ;
import cn.hutool.crypto.asymmetric.AsymmetricCrypto ;
import cn.hutool.crypto.asymmetric.KeyType ;
import cn.hutool.crypto.asymmetric.KeyType ;
import cn.hutool.crypto.asymmetric.RSA ;
import cn.hutool.crypto.asymmetric.RSA ;
import cn.hutool.http.HttpRequest ;
import cn.hutool.http.HttpRequest ;
@ -12,13 +13,20 @@ import com.yxt.supervise.gf.api.utils.RsaUtil;
import com.yxt.supervise.gf.shanhai.ShRequester ;
import com.yxt.supervise.gf.shanhai.ShRequester ;
import com.yxt.supervise.gf.shanhai.resp.BaseResponse ;
import com.yxt.supervise.gf.shanhai.resp.BaseResponse ;
import org.junit.Test ;
import org.junit.Test ;
import sun.misc.BASE64Decoder ;
import java.security.KeyFactory ;
import java.security.interfaces.RSAPrivateKey ;
import java.security.interfaces.RSAPublicKey ;
import java.security.spec.InvalidKeySpecException ;
import java.security.spec.PKCS8EncodedKeySpec ;
import java.security.spec.X509EncodedKeySpec ;
import java.util.Date ;
import java.util.Date ;
public class SecurTest {
public class SecurTest {
// @Test
// @Test
public void testDate ( ) {
public void testDate ( ) throws Exception {
long l = System . currentTimeMillis ( ) ;
long l = System . currentTimeMillis ( ) ;
// System.out.println("" + l);
// System.out.println("" + l);
// System.out.println(DateUtil.format(new Date(),"yyyyMMddHHmmss"));
// System.out.println(DateUtil.format(new Date(),"yyyyMMddHHmmss"));
@ -39,24 +47,32 @@ public class SecurTest {
String publicKeyBase64 = Base64 . encode ( publicKey ) ;
String publicKeyBase64 = Base64 . encode ( publicKey ) ;
RSA rsa = new RSA ( null , publicKey ) ;
RSA rsa = new RSA ( null , publicKey ) ;
String s = rsa . encryptBase64 ( data1 , KeyType . PublicKey ) ;
System . out . println ( s ) ;
// String data = SecureUtil.rsa(privateKeyBase64, publicKeyBase64).encryptBase64(data1, KeyType.PublicKey);
// String data = SecureUtil.rsa(privateKeyBase64, publicKeyBase64).encryptBase64(data1, KeyType.PublicKey);
byte [ ] encrypt = rsa . encrypt ( StrUtil . bytes ( data1 , CharsetUtil . CHARSET_UTF_8 ) , KeyType . PublicKey ) ;
// byte[] encrypt = rsa.encrypt(StrUtil.bytes(data1, CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
String data = StrUtil . str ( encrypt , CharsetUtil . CHARSET_UTF_8 ) ;
// String data = StrUtil.str(encrypt, CharsetUtil.CHARSET_UTF_8);
System . out . println ( data ) ;
// System.out.println(data);
// AsymmetricCrypto asymmetricCrypto = new AsymmetricCrypto("RSA", null,
// getRSAPublidKeyBybase64(publicKey));
//
// String s1 = asymmetricCrypto.encryptBase64(data1, KeyType.PublicKey);
// System.out.println(s1);
// String body = HttpRequest.get("http://hf-service.tiefaos.com/api/system/apply_material/index")
// String body = HttpRequest.get("http://hf-service.tiefaos.com/api/system/apply_material/index")
// String data = "jiq07RIXsX/YwIkXCK4VdhIZcnuFHd+ERekZzMdZT7yxGAyON4s/qtJeJcG9z6uJMtqSUKWTvREc4CNsyuStXacJ2bGgKCzFcUTwwBUJ7AQ2ybhedpkA7JWqJ1UjooLGUYZfoTduygH2r7LG0qRgigQGD3WdB53WLuC11kT5wAzMnFtbBDHpH78oNjGhvmWpaR6meDCI2OM0GtCWwBxOagCYt8V5DfD47VyNHYn0xFRva4GFBF6K19061h1cu68eXxfIZj+clMweGlICgeXhktq8Z1T0XmbahFjhyTmdXuRxZBeQkLsot00XJHwQ48B6Z/VdOPpqoD95NTngRdV3+A==";
// String data = "jiq07RIXsX/YwIkXCK4VdhIZcnuFHd+ERekZzMdZT7yxGAyON4s/qtJeJcG9z6uJMtqSUKWTvREc4CNsyuStXacJ2bGgKCzFcUTwwBUJ7AQ2ybhedpkA7JWqJ1UjooLGUYZfoTduygH2r7LG0qRgigQGD3WdB53WLuC11kT5wAzMnFtbBDHpH78oNjGhvmWpaR6meDCI2OM0GtCWwBxOagCYt8V5DfD47VyNHYn0xFRva4GFBF6K19061h1cu68eXxfIZj+clMweGlICgeXhktq8Z1T0XmbahFjhyTmdXuRxZBeQkLsot00XJHwQ48B6Z/VdOPpqoD95NTngRdV3+A==";
// String date = "1683516744";
// String date = "1683516744";
String body = HttpRequest . get ( "http://hf.lx-obj.top/api/system/apply_material/index" )
String body = HttpRequest . get ( "http://hf.lx-obj.top/api/system/apply_material/index" )
. header ( "data" , data )
. header ( "data" , s )
. header ( "date" , date )
. header ( "date" , date )
. execute ( )
. execute ( )
. body ( ) ;
. body ( ) ;
System . out . println ( body ) ;
System . out . println ( body ) ;
}
}
@Test
// @Test
public void testRequester ( ) {
public void testRequester ( ) {
BaseResponse api$system$applyMaterial$index = ShRequester . getApi$system$apply_material$index ( null ) ;
BaseResponse api$system$applyMaterial$index = ShRequester . getApi$system$apply_material$index ( null ) ;
System . out . println ( api$system$applyMaterial$index ) ;
System . out . println ( api$system$applyMaterial$index ) ;
@ -64,4 +80,55 @@ public class SecurTest {
// String api$system$applyMaterial$getActualOrderMaterial = ShRequester.getApi$system$apply_material$get_actual_order_material("10888");
// String api$system$applyMaterial$getActualOrderMaterial = ShRequester.getApi$system$apply_material$get_actual_order_material("10888");
// System.out.println(api$system$applyMaterial$getActualOrderMaterial);
// System.out.println(api$system$applyMaterial$getActualOrderMaterial);
}
}
/ * *
* @param
* @return
* @desc : 将字符串转换成RSAPublicKey类型
* @date 2020 - 6 - 12 11 : 03 : 05
* /
public static RSAPublicKey getRSAPublidKeyBybase64 ( String base64s ) throws Exception {
X509EncodedKeySpec keySpec = new X509EncodedKeySpec ( ( new BASE64Decoder ( ) ) . decodeBuffer ( base64s ) ) ;
RSAPublicKey publicKey = null ;
KeyFactory keyFactory = KeyFactory . getInstance ( "RSA" ) ;
try {
publicKey = ( RSAPublicKey ) keyFactory . generatePublic ( keySpec ) ;
} catch ( InvalidKeySpecException e ) {
e . printStackTrace ( ) ;
}
return publicKey ;
}
/ * *
* @param
* @return
* @desc : 将字符串转换成RSAPrivateKey类型
* @date 2020 - 6 - 12 11 : 03 : 01
* /
public static RSAPrivateKey getRSAPrivateKeyBybase64 ( String base64s ) throws Exception {
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec ( ( new BASE64Decoder ( ) ) . decodeBuffer ( base64s ) ) ;
RSAPrivateKey privateKey = null ;
KeyFactory keyFactory = KeyFactory . getInstance ( "RSA" ) ;
try {
privateKey = ( RSAPrivateKey ) keyFactory . generatePrivate ( keySpec ) ;
} catch ( InvalidKeySpecException var4 ) {
var4 . printStackTrace ( ) ;
}
return privateKey ;
}
// @Test
public void testXxx ( ) throws Exception {
AsymmetricCrypto asymmetricCrypto = new AsymmetricCrypto ( "RSA" , getRSAPrivateKeyBybase64 ( "私钥解密" ) ,
getRSAPublidKeyBybase64 ( "公钥加密" ) ) ;
String s1 = asymmetricCrypto . encryptBase64 ( "你好呀" , KeyType . PublicKey ) ;
System . out . println ( s1 ) ;
String s = asymmetricCrypto . decryptStr ( s1 , KeyType . PrivateKey ) ;
System . out . println ( s ) ;
}
}
}