update
This commit is contained in:
@ -83,10 +83,27 @@ export class DnsSec {
|
||||
}
|
||||
|
||||
public signData(data: Buffer): Buffer {
|
||||
// Sign the data using the private key
|
||||
const keyPair = this.ec!.keyFromPrivate(this.keyPair.privateKey, 'hex');
|
||||
const signature = keyPair.sign(plugins.crypto.createHash('sha256').update(data).digest());
|
||||
return Buffer.from(signature.toDER());
|
||||
switch (this.zone.algorithm) {
|
||||
case 'ECDSA':
|
||||
if (!this.ec) throw new Error('EC instance is not initialized.');
|
||||
const ecKeyPair = this.ec.keyFromPrivate(this.keyPair.privateKey, 'hex');
|
||||
const ecSignature = ecKeyPair.sign(plugins.crypto.createHash('sha256').update(data).digest());
|
||||
return Buffer.from(ecSignature.toDER());
|
||||
|
||||
case 'ED25519':
|
||||
if (!this.eddsa) throw new Error('EdDSA instance is not initialized.');
|
||||
const edKeyPair = this.eddsa.keyFromSecret(Buffer.from(this.keyPair.privateKey, 'hex'));
|
||||
// ED25519 doesn't need a separate hash function as it includes the hashing internally
|
||||
const edSignature = edKeyPair.sign(data);
|
||||
// Convert the signature to the correct format for Buffer.from
|
||||
return Buffer.from(edSignature.toBytes());
|
||||
|
||||
case 'RSA':
|
||||
throw new Error('RSA signing is not yet implemented.');
|
||||
|
||||
default:
|
||||
throw new Error(`Unsupported algorithm: ${this.zone.algorithm}`);
|
||||
}
|
||||
}
|
||||
|
||||
private generateDNSKEY(): Buffer {
|
||||
@ -169,4 +186,4 @@ export class DnsSec {
|
||||
const dnskeyRecord = this.getDNSKEYRecord();
|
||||
return { keyPair: this.keyPair, dsRecord, dnskeyRecord };
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user