1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/asn1.js/lib/asn1/encoders/pem.js

24 lines
614 B
JavaScript
Raw Normal View History

2024-01-16 21:26:16 +08:00
'use strict';
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const inherits = require('inherits');
const DEREncoder = require('./der');
2023-12-18 13:12:25 +08:00
function PEMEncoder(entity) {
DEREncoder.call(this, entity);
this.enc = 'pem';
2024-01-16 21:26:16 +08:00
}
2023-12-18 13:12:25 +08:00
inherits(PEMEncoder, DEREncoder);
module.exports = PEMEncoder;
PEMEncoder.prototype.encode = function encode(data, options) {
2024-01-16 21:26:16 +08:00
const buf = DEREncoder.prototype.encode.call(this, data);
2023-12-18 13:12:25 +08:00
2024-01-16 21:26:16 +08:00
const p = buf.toString('base64');
const out = [ '-----BEGIN ' + options.label + '-----' ];
for (let i = 0; i < p.length; i += 64)
2023-12-18 13:12:25 +08:00
out.push(p.slice(i, i + 64));
out.push('-----END ' + options.label + '-----');
return out.join('\n');
};