rsa-compat.js/tests/reciprocate.js

30 lines
801 B
JavaScript

'use strict';
var RSA = require('../').RSA;
var fs = require('fs');
var path = require('path');
var privkeyPemRef = fs.readFileSync(path.join(__dirname, 'privkey.pem'), 'ascii');
var privkeyJwkRef = JSON.parse(fs.readFileSync(path.join(__dirname, 'privkey.jwk'), 'ascii'));
var refs = {
privPem: RSA.exportPrivatePem({ privateKeyJwk: privkeyJwkRef })
, privJwk: RSA.exportPrivateJwk({ privateKeyPem: privkeyPemRef })
};
console.log('');
console.log('valid pem', privkeyPemRef === refs.privPem);
if (privkeyPemRef !== refs.privPem) {
console.log(privkeyPemRef);
console.log(refs.privPem);
}
console.log('');
console.log('valid jwk', privkeyJwkRef.n === refs.privJwk.n);
if (privkeyJwkRef.n !== refs.privJwk.n) {
console.log(privkeyJwkRef);
console.log(refs.privJwk);
}
console.log('');