Использование OpenPGP.js v1.3.0 Я могу успешно создать пару открытого и закрытого ключей и зашифровать/дешифровать в порядке.Вычислить ключ открытого ключа с помощью openpgp.js
Я изо всех сил, чтобы получить идентификатор ключа с помощью этой функции (находится в openpgp.js и public_key.js):
/**
* Calculates the key id of the key
* @return {String} A 8 byte key id
*/
PublicKey.prototype.getKeyId = function() {
if (this.keyid) {
return this.keyid;
}
this.keyid = new type_keyid();
if (this.version == 4) {
this.keyid.read(util.hex2bin(this.getFingerprint()).substr(12, 8));
} else if (this.version == 3) {
this.keyid.read(this.mpi[0].write().substr(-8));
}
return this.keyid;
};
ОткрытыйКлюч() также в openpgp.js:
/**
* @constructor
*/
function PublicKey() {
this.tag = enums.packet.publicKey;
this.version = 4;
/** Key creation date.
* @type {Date} */
this.created = new Date();
/** A list of multiprecision integers
* @type {module:type/mpi} */
this.mpi = [];
/** Public key algorithm
* @type {module:enums.publicKey} */
this.algorithm = 'rsa_sign';
// time in days (V3 only)
this.expirationTimeV3 = 0;
/**
* Fingerprint in lowercase hex
* @type {String}
*/
this.fingerprint = null;
/**
* Keyid
* @type {module:type/keyid}
*/
this.keyid = null;
}
и пытается получить идентификатор ключа, как это:
var publickey = openpgp.key.readArmored(myPublicKey);
//var keyID = openpgp.packet.PublicKey(publickey).getKeyId()[0].toHex();
var keyID = openpgp.PublicKey(publickey).getKeyId()[0].toHex();
console.log(keyID);
, который дает мне ошибку: TypeError: openpgp.PublicKey не является функцией.
Спасибо.
Как насчет 'publickey.keys [0] .getKeyId(). ToHex();'? –
try: openpgp.PublicKey.publickey.keys [0] .getKeyId(). ToHex() получил errror: openpgp.PublicKey не определено – user2677034
Попробуйте то, что я написал вместо этого ... –