struct PersonInfo { name: string, age: integer }
PersonInfo ::= SEQUENCE { name UTF8String, age INTEGER }
const asn1 = require('asn1.js'); const person = new PersonInfo({ name: '张三', age: 23 }); const schema = { PersonInfo: { type: 'seq', value: [ { type: 'utf8str', value: person.name }, { type: 'int', value: person.age } ] } }; const encoded = asn1.encode(person, schema, 'der');
const base64Encoded = Buffer.from(encoded, 'binary').toString('base64');