使用openpgp.js计算公钥的密钥id
Calculate the key id of public key using openpgp.js
使用OpenPGP.js v1.3.0,我可以成功创建公钥/私钥对并加密/解密。
我很难使用这个函数(在openpgp.js和public_key.js中找到)获得密钥id:
/**
* 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;
};
PublicKey()也在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;
}
并试图获得这样的密钥id:
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);
这给了我一个错误:类型错误:openpgp。PublicKey不是函数。
谢谢。
我在这里问了这个问题:http://www.mail-archive.com/list@openpgpjs.org/msg00932.html得到了非常有帮助的答复。
var openpgp = window.openpgp;
var testPublicKey = sessionStorage.getItem('testPublicKey');
var foundKeys = openpgp.key.readArmored(testPublicKey).keys;
if (!foundKeys || foundKeys.length !== 1) {
throw new Error("Key not read, or more than one key found");
}
var pubKey = foundKeys[0]; foundKeys = null;
var getFingerprint = function (key) {
// openpgp.key <- Class
// key <- Instance received by params
return key.primaryKey.fingerprint;
};
var getKeyId = function (key) {
return key.primaryKey.getKeyId().toHex();
}
console.log(getFingerprint(pubKey));
console.log(getKeyId(pubKey));
相关文章:
- API密钥使用和检查示例
- react.js中的密钥绑定
- JS对象密钥序列
- 似乎无法使用javascript从AWS 3S中删除密钥
- 加载两个具有相同父密钥名称的json文件
- 如何获取$data.Entity的密钥
- Angular ngRepeat:重复错误(尽管没有重复的密钥)
- CryptoJS和密钥/IV长度
- 基于api密钥的NodeJS web服务
- 输入密钥和firefox提示
- React Rails应用程序中动态子项的密钥分配问题
- 正在Javascript Cookie中设置重复密钥
- 通过localStorage中的密钥获取ID
- 从密钥中获取价值.JavaScript
- Javascript对象中的跨浏览器密钥查找性能
- 如何动态更改玩家id和密钥
- 将 ID 与数组编号匹配并分配密钥敲除 js
- 将会话ID/密钥作为请求参数传递时存在安全风险
- 使用openpgp.js计算公钥的密钥id
- indexedDb-使用两个独立的密钥(本地和服务器ID/联机和脱机)进行保存/更新