public static byte [ ] EncodeSubjectPublicKeyInfo ( byte [ ] algorithm , byte [ ] keyBytes ) throws CoseException { // SPKI ::= SEQUENCE { // algorithm SEQUENCE { // oid = id-ecPublicKey {1 2 840 10045 2} // namedCurve = oid for algorithm // } // subjectPublicKey BIT STRING CONTAINS key bytes // } try { ArrayList < byte [ ] > xxx = new ArrayList < byte [ ] > ( ) ; xxx . add ( algorithm ) ; xxx . add ( new byte [ ] { 3 } ) ; xxx . add ( ComputeLength ( keyBytes . length + 1 ) ) ; xxx . add ( new byte [ ] { 0 } ) ; xxx . add ( keyBytes ) ; return Sequence ( xxx ) ; } catch ( ArrayIndexOutOfBoundsException e ) { System . out . print ( e . toString ( ) ) ; throw e ; } }
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