Package COSE
Class ASN1
- java.lang.Object
-
- COSE.ASN1
-
public class ASN1 extends Object
- Author:
- Jim
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classASN1.TagValueThis class is used internal to the ASN.1 decoding functions.
-
Field Summary
Fields Modifier and Type Field Description static byte[]oid_ecPublicKeystatic byte[]Oid_Ed25519static byte[]Oid_Ed448static byte[]Oid_rsaEncryptionstatic byte[]Oid_secp256r1static byte[]Oid_secp384r1static byte[]Oid_secp521r1static byte[]Oid_X25519static byte[]Oid_X448
-
Constructor Summary
Constructors Constructor Description ASN1()
-
Method Summary
Modifier and Type Method Description static byte[]AlgorithmIdentifier(byte[] oid, byte[] params)static ASN1.TagValueDecodeCompound(int offset, byte[] encoding)Decode an array of bytes which is supposed to be an ASN.1 encoded structure.static ArrayList<ASN1.TagValue>DecodePKCS8EC(ArrayList<ASN1.TagValue> pkcs8)Decode an EC PKCS#8 private key octet stringstatic ArrayList<ASN1.TagValue>DecodePKCS8RSA(ArrayList<ASN1.TagValue> pkcs8)Decode a RSA PKCS#8 private key octet stringstatic ArrayList<ASN1.TagValue>DecodePKCS8Structure(byte[] encodedData)Decode a PKCS#8 private key structure, leaving the private key as an octetstring.static ArrayList<ASN1.TagValue>DecodeSubjectPublicKeyInfo(byte[] encoding)static byte[]EncodeEcPrivateKey(byte[] oid, byte[] keyBytes, byte[] spki)Encode an EC Private keystatic byte[]EncodeOctetString(byte[] data)static byte[]EncodePKCS8(byte[] algorithm, byte[] keyBytes, byte[] spki)Encode a private key into a PKCS#8 private key structure.static byte[]EncodeSignature(byte[] r, byte[] s)static byte[]EncodeSubjectPublicKeyInfo(byte[] algorithm, byte[] keyBytes)Encode a subject public key info structure from an OID and the data bytes for the key This function assumes that we are encoding an EC Public key.d
-
-
-
Field Detail
-
Oid_secp256r1
public static final byte[] Oid_secp256r1
-
Oid_secp384r1
public static final byte[] Oid_secp384r1
-
Oid_secp521r1
public static final byte[] Oid_secp521r1
-
oid_ecPublicKey
public static final byte[] oid_ecPublicKey
-
Oid_X25519
public static final byte[] Oid_X25519
-
Oid_X448
public static final byte[] Oid_X448
-
Oid_Ed25519
public static final byte[] Oid_Ed25519
-
Oid_Ed448
public static final byte[] Oid_Ed448
-
Oid_rsaEncryption
public static final byte[] Oid_rsaEncryption
-
-
Method Detail
-
EncodeSubjectPublicKeyInfo
public static byte[] EncodeSubjectPublicKeyInfo(byte[] algorithm, byte[] keyBytes) throws CoseExceptionEncode a subject public key info structure from an OID and the data bytes for the key This function assumes that we are encoding an EC Public key.d- Parameters:
algorithm- - encoded Object IdentifierkeyBytes- - encoded key bytes- Returns:
- - encoded SPKI
- Throws:
CoseException- - ASN encoding error.
-
EncodeEcPrivateKey
public static byte[] EncodeEcPrivateKey(byte[] oid, byte[] keyBytes, byte[] spki) throws CoseExceptionEncode an EC Private key- Parameters:
oid- - curve to usekeyBytes- - bytes of the keyspki- - optional SPKI- Returns:
- encoded private key
- Throws:
CoseException- - from lower level
-
DecodeSubjectPublicKeyInfo
public static ArrayList<ASN1.TagValue> DecodeSubjectPublicKeyInfo(byte[] encoding) throws CoseException
- Throws:
CoseException
-
DecodeCompound
public static ASN1.TagValue DecodeCompound(int offset, byte[] encoding) throws CoseException
Decode an array of bytes which is supposed to be an ASN.1 encoded structure. This code does the decoding w/o any reference to a schema for what is being decoded so it returns type and value pairs rather than converting the values to the correct underlying data type. One oddity that needs to be observed is that Object Identifiers do not have the type and length removed from them. This is because we do a byte wise comparison and started doing the entire item rather than just the value portion. M00BUG - we should check that we don't overflow during the decoding process.- Parameters:
offset- - starting offset in array to begin decodingencoding- - bytes of the ASN.1 encoded value- Returns:
- Decoded structure
- Throws:
CoseException- - ASN.1 encoding errors
-
EncodePKCS8
public static byte[] EncodePKCS8(byte[] algorithm, byte[] keyBytes, byte[] spki) throws CoseExceptionEncode a private key into a PKCS#8 private key structure.- Parameters:
algorithm- - EC curve OIDkeyBytes- - raw bytes of the keyspki- - optional subject public key info structure to include- Returns:
- byte array of encoded bytes
- Throws:
CoseException- - ASN.1 encoding errors
-
DecodePKCS8Structure
public static ArrayList<ASN1.TagValue> DecodePKCS8Structure(byte[] encodedData) throws CoseException
Decode a PKCS#8 private key structure, leaving the private key as an octetstring.- Parameters:
encodedData- bytes containing the private key- Returns:
- tag/value from the decoded object
- Throws:
CoseException- - ASN.1 encoding errors
-
DecodePKCS8RSA
public static ArrayList<ASN1.TagValue> DecodePKCS8RSA(ArrayList<ASN1.TagValue> pkcs8) throws CoseException
Decode a RSA PKCS#8 private key octet string- Parameters:
pkcs8- The decoded PKCS#8 structure- Returns:
- tag/value from the decoded object
- Throws:
CoseException- - ASN.1 encoding errors
-
DecodePKCS8EC
public static ArrayList<ASN1.TagValue> DecodePKCS8EC(ArrayList<ASN1.TagValue> pkcs8) throws CoseException
Decode an EC PKCS#8 private key octet string- Parameters:
pkcs8- The decoded PKCS#8 structure- Returns:
- tag/value from the decoded object
- Throws:
CoseException- - ASN.1 encoding errors
-
EncodeSignature
public static byte[] EncodeSignature(byte[] r, byte[] s) throws CoseException- Throws:
CoseException
-
EncodeOctetString
public static byte[] EncodeOctetString(byte[] data) throws CoseException- Throws:
CoseException
-
AlgorithmIdentifier
public static byte[] AlgorithmIdentifier(byte[] oid, byte[] params) throws CoseException- Throws:
CoseException
-
-