From f83a99b82300ad1fcb77bb26633214649d1d871e Mon Sep 17 00:00:00 2001 From: Aditya Belsare Date: Mon, 7 Jul 2025 12:01:17 -0700 Subject: [PATCH] Add a method to export the public key as a BigInteger --- src/com/google/cose/OkpKey.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/com/google/cose/OkpKey.java b/src/com/google/cose/OkpKey.java index 58552f1..c39ece1 100644 --- a/src/com/google/cose/OkpKey.java +++ b/src/com/google/cose/OkpKey.java @@ -9,6 +9,7 @@ import com.google.cose.exceptions.CoseException; import com.google.cose.utils.CborUtils; import com.google.cose.utils.Headers; +import java.math.BigInteger; import java.util.Arrays; /** @@ -41,6 +42,15 @@ public byte[] getPublicKeyBytes() { return Arrays.copyOf(publicKeyBytes, publicKeyBytes.length); } + public BigInteger getPublicKeyBytesAsBigInteger() { + // Reverse the bytes to get the correct big-endian representation. + byte[] reversedBytes = new byte[publicKeyBytes.length]; + for (int i = 0; i < publicKeyBytes.length; i++) { + reversedBytes[i] = publicKeyBytes[publicKeyBytes.length - 1 - i]; + } + return new BigInteger(1, reversedBytes); + } + /** Recursive builder to build out the Ec2 key and its subclasses. */ abstract static class Builder> extends CoseKey.Builder { private Integer curve = null;