Add getKeyByPublicKey method

This commit is contained in:
Vladimir Privezenov
2025-12-24 19:29:52 +03:00
parent 43b0ecfa19
commit 68447041f3
2 changed files with 18 additions and 3 deletions

View File

@ -86,6 +86,13 @@ KeyStorage.prototype.addKeys = function (keys) {
KeyStorage.prototype.setKeys = function (keys) {
this.keys = keys;
};
KeyStorage.prototype.getKeyByPublicKey = function(publicKey) {
KeyStorage.prototype.getKeyByPublicKey = function(publicKeyData) {
const reader = new BinaryReader(publicKeyData, publicKeyData.length);
const publicKey = readObject(reader);
for (let i = 0; i < this.keys.length; i++) {
if (this.keys[i].isHavePublicKey(publicKey)) {
return this.keys[i];
}
}
return null;
};

View File

@ -124,6 +124,9 @@ WebKeyPair.prototype.initKey = function (masterPassword) {
const crypto = getCrypto();
return Promise.all([crypto.initKey(this.publicKey), crypto.initKey(this.privateKey, masterPassword)]);
};
WebKeyPair.prototype.isHavePublicKey = function(publicKey) {
return this.publicKey.isEqual(publicKey);
};
export function WebSignKeyPair() {
WebKeyPair.call(this);
@ -296,6 +299,9 @@ WebPublicKey.prototype.verify = function(data) {
WebPublicKey.prototype.getImportFormat = function () {
return c_oAscExportKeyFormat.spki;
}
WebPublicKey.prototype.isEqual = function (publicKey) {
return this.binaryKey === publicKey.binaryKey;
};
export function WebPublicSignKey() {
WebPublicKey.call(this);
@ -399,7 +405,9 @@ WebSymmetricKey.prototype.getImportCryptoParams = function() {
WebSymmetricKey.prototype.getCryptoUsages = function() {
return ["encrypt", "decrypt"];
};
WebSymmetricKey.prototype.isHavePublicKey = function(publicKey) {
return false;
};
export function EncryptData(encryptData, params) {
CryptoBase.call(this);