11package com .api .util .ApiSecurity ;
22
3- import org .bouncycastle .asn1 .ASN1Sequence ;
4- import org .bouncycastle .asn1 .DERInteger ;
53import org .bouncycastle .asn1 .x509 .SubjectPublicKeyInfo ;
64import org .bouncycastle .openssl .PEMDecryptorProvider ;
75import org .bouncycastle .openssl .PEMEncryptedKeyPair ;
1513import javax .crypto .Mac ;
1614import javax .crypto .spec .SecretKeySpec ;
1715
18- import java .io .BufferedReader ;
1916import java .io .File ;
2017import java .io .FileInputStream ;
2118import java .io .FileNotFoundException ;
2219import java .io .FileReader ;
2320import java .io .IOException ;
24- import java .io .InputStreamReader ;
2521import java .io .UnsupportedEncodingException ;
26- import java .math .BigInteger ;
2722import java .net .URI ;
2823import java .net .URISyntaxException ;
2924import java .nio .charset .StandardCharsets ;
3025import java .security .*;
3126import java .security .cert .CertificateException ;
3227import java .security .cert .CertificateFactory ;
3328import java .security .cert .X509Certificate ;
34- import java .security .interfaces .RSAPublicKey ;
35- import java .security .spec .InvalidKeySpecException ;
36- import java .security .spec .PKCS8EncodedKeySpec ;
37- import java .security .spec .RSAPrivateCrtKeySpec ;
38- import java .security .spec .RSAPrivateKeySpec ;
39- import java .security .spec .X509EncodedKeySpec ;
4029import java .util .Base64 ;
41- import java .util .Enumeration ;
4230
4331
4432/**
@@ -573,12 +561,6 @@ public static String getSignatureToken(
573561 }
574562 timestamp = timestamp != null ? timestamp : Long .toString (getNewTimestamp ());
575563
576-
577- // if (secret != null) {
578- // signatureMethod = "HMACSHA256";
579- // } else {
580- // signatureMethod = "SHA256withRSA";
581- // }
582564 if (authPrefix .toLowerCase ().contains ("l1" )){
583565 signatureMethod = "HMACSHA256" ;
584566 }else if (authPrefix .toLowerCase ().contains ("l2" )){
@@ -591,9 +573,9 @@ public static String getSignatureToken(
591573 , appId , urlPath , httpMethod
592574 , formList , nonce , timestamp );
593575
594- if (signatureMethod . equals ( "HMACSHA256" )) {
576+ if ("HMACSHA256" . equals ( signatureMethod )) {
595577 base64Token = getHMACSignature (baseString , secret );
596- } else if (signatureMethod . equals ( "SHA256withRSA" )){
578+ } else if ("SHA256withRSA" . equals ( signatureMethod )){
597579 PrivateKey privateKey = null ;
598580 if (null !=fileName && (fileName .contains (".key" )||fileName .contains (".pem" ))){
599581 privateKey = ApiSigning .getPrivateKeyPEM (fileName , password );
0 commit comments