Skip to content

Commit eac93aa

Browse files
asbelsaresethmoo
authored andcommitted
Add a method to export the public key as a
BigInteger
1 parent 9add8ae commit eac93aa

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/com/google/cose/OkpKey.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.cose.exceptions.CoseException;
1010
import com.google.cose.utils.CborUtils;
1111
import com.google.cose.utils.Headers;
12+
import java.math.BigInteger;
1213
import java.util.Arrays;
1314

1415
/**
@@ -41,6 +42,15 @@ public byte[] getPublicKeyBytes() {
4142
return Arrays.copyOf(publicKeyBytes, publicKeyBytes.length);
4243
}
4344

45+
public BigInteger getPublicKeyBytesAsBigInteger() {
46+
// Reverse the bytes to get the correct big-endian representation.
47+
byte[] reversedBytes = new byte[publicKeyBytes.length];
48+
for (int i = 0; i < publicKeyBytes.length; i++) {
49+
reversedBytes[i] = publicKeyBytes[publicKeyBytes.length - 1 - i];
50+
}
51+
return new BigInteger(1, reversedBytes);
52+
}
53+
4454
/** Recursive builder to build out the Ec2 key and its subclasses. */
4555
abstract static class Builder<T extends Builder<T>> extends CoseKey.Builder<T> {
4656
private Integer curve = null;

0 commit comments

Comments
 (0)