Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions webull-openapi-java-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,21 @@
</plugins>
</build>

<profiles>
<!-- Profile applied to Java 9 and all newer versions -->
<profile>
<id>java-post-8</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class HmacSHA1Signer implements Signer {

Expand All @@ -36,7 +36,7 @@ public String getSign(String source, String secret) {
Mac mac = Mac.getInstance(ALGORITHM);
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), ALGORITHM));
byte[] signData = mac.doFinal(source.getBytes(StandardCharsets.UTF_8));
return DatatypeConverter.printBase64Binary(signData);
return Base64.getEncoder().encodeToString(signData);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new ClientException(ErrorCode.INVALID_CREDENTIAL, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

public class HmacSHA256Signer implements Signer {

Expand All @@ -37,7 +37,7 @@ public String getSign(String source, String secret) {
Mac mac = Mac.getInstance(ALGORITHM);
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), ALGORITHM));
byte[] signData = mac.doFinal(source.getBytes(StandardCharsets.UTF_8));
return DatatypeConverter.printBase64Binary(signData);
return Base64.getEncoder().encodeToString(signData);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new ClientException(ErrorCode.INVALID_CREDENTIAL, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.webull.openapi.core.exception.ClientException;
import com.webull.openapi.core.exception.ErrorCode;

import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
Expand All @@ -28,6 +27,7 @@
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;

public class SHA256withRSASigner implements Signer {

Expand All @@ -39,12 +39,12 @@ public String getSign(String source, String secret) {
try {
Signature rsaSign = Signature.getInstance(SignAlgorithm.SHA256_WITH_RSA.getSignerName());
KeyFactory kf = KeyFactory.getInstance(ALGORITHM);
byte[] keySpec = DatatypeConverter.parseBase64Binary(secret);
byte[] keySpec = Base64.getDecoder().decode(secret);
PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(keySpec));
rsaSign.initSign(privateKey);
rsaSign.update(source.getBytes(StandardCharsets.UTF_8));
byte[] sign = rsaSign.sign();
return DatatypeConverter.printBase64Binary(sign);
return Base64.getEncoder().encodeToString(sign);
} catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException | SignatureException e) {
throw new ClientException(ErrorCode.INVALID_CREDENTIAL, e);
}
Expand Down