You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pem.js 590B

123456789101112131415161718192021
  1. var inherits = require('inherits');
  2. var DEREncoder = require('./der');
  3. function PEMEncoder(entity) {
  4. DEREncoder.call(this, entity);
  5. this.enc = 'pem';
  6. };
  7. inherits(PEMEncoder, DEREncoder);
  8. module.exports = PEMEncoder;
  9. PEMEncoder.prototype.encode = function encode(data, options) {
  10. var buf = DEREncoder.prototype.encode.call(this, data);
  11. var p = buf.toString('base64');
  12. var out = [ '-----BEGIN ' + options.label + '-----' ];
  13. for (var i = 0; i < p.length; i += 64)
  14. out.push(p.slice(i, i + 64));
  15. out.push('-----END ' + options.label + '-----');
  16. return out.join('\n');
  17. };