|
|
@@ -1,59 +0,0 @@ |
|
|
|
package work.xuye.common.utils; |
|
|
|
|
|
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.util.DigestUtils; |
|
|
|
import work.xuye.common.dto.HttpRequestParams; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.security.KeyFactory; |
|
|
|
import java.security.PrivateKey; |
|
|
|
import java.security.Signature; |
|
|
|
import java.security.spec.PKCS8EncodedKeySpec; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author yechuan |
|
|
|
* @since 2023/8/7 15:08 |
|
|
|
**/ |
|
|
|
@Component |
|
|
|
public class SignatureUtil { |
|
|
|
|
|
|
|
private final static String privateKey = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANTyWsgvVOW6lNH4\n" + |
|
|
|
"koggbORNIdM0mw+klkTfAZJ8hM9SvxaPWgo55dU1zp46nUs15ZStf/A4EmOeh4jA\n" + |
|
|
|
"SLqHf3Zd2WJc5izjEm70pnwHXRCjOA8i4nR6ia0fpzZPf+FNqElmvsfrvqk185cf\n" + |
|
|
|
"kAXk2RoXSAykUi+2UMK6TlTaHmqXAgMBAAECgYAmCFcQc+us0CMuUUASkgAA0ond\n" + |
|
|
|
"CAM9yv6PtGi6egTaZoP8ioPhWa/j4aVSe1OGkEy9vjMge1NFeZXpZbZXokWwUdmi\n" + |
|
|
|
"xxOcCYgYKebJ0Fmssvj/GSRL93B1JlXs88MdedAGlef1b1IyURUSDbkkbOZmHnON\n" + |
|
|
|
"OgkoSafcB+JFx6Ea8QJBAPTaiAZSsco9e23EMXfhy+h7CjYYY8LJ+gBrnEZV2jns\n" + |
|
|
|
"O7i2W/2c9sEzexG8C/W1oEbEDsfkmCKvf/mQ+dJb0d8CQQDeo/yuk5Z0W+yBos5U\n" + |
|
|
|
"h0vjlAJzVL812QNv02bogmGaS7y3Ao1+/cVeTWSrlEjjM2tcbnpFtOgFtLBl1lFX\n" + |
|
|
|
"9q5JAkB6gskimMe6UC7sygiSWhjjdoSycluf/90lzrH/gz9QUgHDtwKqD5prKq3+\n" + |
|
|
|
"Pp+hTkImhjx7CcaRPEyE+2P0O9rzAkEAq2XJgEhkmn2uDHrepxplZPUsEcebUIQZ\n" + |
|
|
|
"7jvsTHEbXKKTzLwtXCdXi2q/ZovItQh/zW/Lt+A2gzYAWtXsV3Cz6QJBAJUTb8kM\n" + |
|
|
|
"5iUYlWupmS6kOSfYFOqrVvI3w9kZUocsxv338dpzuKxikkIxAfiBTtbVXawEkF48\n" + |
|
|
|
"tTSQsDJmnXj2Hhw="; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String signature(String content) throws Exception { |
|
|
|
|
|
|
|
byte[] decode = Base64.decodeBase64(privateKey); |
|
|
|
PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(decode); |
|
|
|
PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(priPKCS8); |
|
|
|
String md5 = DigestUtils.md5DigestAsHex(content.getBytes(StandardCharsets.UTF_8)).toUpperCase(); |
|
|
|
Signature signature = Signature.getInstance("SHA1WithRSA"); |
|
|
|
signature.initSign(priKey); |
|
|
|
signature.update(md5.getBytes(StandardCharsets.UTF_8)); |
|
|
|
return Base64.encodeBase64String(signature.sign()).trim(); |
|
|
|
} |
|
|
|
|
|
|
|
public String packageContent(HttpRequestParams params, String timestamp, String body) { |
|
|
|
return "ENCRYPT-ALGORITHM" + "=" + "RSA" + |
|
|
|
"&" + |
|
|
|
"PARAMS" + "=" + body + |
|
|
|
"&" + |
|
|
|
"TIMESTAMP" + "=" + timestamp; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |