Aracılığıyla paylaş


CryptographyClient class

Azure Key Vault anahtarında veya yerel bir JsonWebKeyüzerinde şifreleme işlemleri gerçekleştirmek için kullanılan bir istemci.

Oluşturucular

CryptographyClient(JsonWebKey)

Yerel modda verilen anahtar için Şifreleme istemcisinin yeni bir örneğini oluşturur.

Örnek kullanım:

import { CryptographyClient } from "@azure/keyvault-keys";

const jsonWebKey = {
  kty: "RSA",
  kid: "test-key-123",
  use: "sig",
  alg: "RS256",
  n: new Uint8Array([112, 34, 56, 98, 123, 244, 200, 99]),
  e: new Uint8Array([1, 0, 1]),
  d: new Uint8Array([45, 67, 89, 23, 144, 200, 76, 233]),
  p: new Uint8Array([34, 89, 100, 77, 204, 56, 29, 77]),
  q: new Uint8Array([78, 99, 201, 45, 188, 34, 67, 90]),
  dp: new Uint8Array([23, 45, 78, 56, 200, 144, 32, 67]),
  dq: new Uint8Array([12, 67, 89, 144, 99, 56, 23, 45]),
  qi: new Uint8Array([78, 90, 45, 201, 34, 67, 120, 55]),
};
const client = new CryptographyClient(jsonWebKey);
CryptographyClient(string | KeyVaultKey, TokenCredential, CryptographyClientOptions)

Verilen anahtar için Şifreleme istemcisinin yeni bir örneğini oluşturur

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

// Create or retrieve a key from the keyvault
const myKey = await client.createKey("MyKey", "RSA");

// Lastly, create our cryptography client and connect to the service
const cryptographyClient = new CryptographyClient(myKey, credential);

Özellikler

keyID

İstemci için şifreleme işlemleri gerçekleştirmek için kullanılan anahtarın kimliği.

vaultUrl

Kasanın temel URL'si. Yerel bir JsonWebKey kullanılırsa vaultUrl boş olur.

Yöntemler

decrypt(DecryptParameters, DecryptOptions)

Belirtilen şifre çözme parametreleriyle verilen şifreleme metninin şifresini çözer. Şifre çözme parametrelerinde kullanılan algoritmaya bağlı olarak, olası şifre çözme parametreleri kümesi değişir.

Microsoft, önce bir HMAC kullanarak şifre metninin bütünlüğünü sağlamadan CBC kullanmamanızı önerir. Daha fazla bilgi için bkz. https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode.

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);

const decryptResult = await cryptographyClient.decrypt({
  algorithm: "RSA1_5",
  ciphertext: encryptResult.result,
});
console.log("decrypt result: ", decryptResult.result.toString());
decrypt(string, Uint8Array, DecryptOptions)

Belirtilen şifreleme algoritmasıyla verilen şifreleme metninin şifresini çözer

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);

const decryptResult = await cryptographyClient.decrypt({
  algorithm: "RSA1_5",
  ciphertext: encryptResult.result,
});
console.log("decrypt result: ", decryptResult.result.toString());

Microsoft, önce bir HMAC kullanarak şifre metninin bütünlüğünü sağlamadan CBC kullanmamanızı önerir. Daha fazla bilgi için bkz. https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode.

encrypt(EncryptParameters, EncryptOptions)

Belirtilen düz metni belirtilen şifreleme parametreleriyle şifreler. Şifreleme parametrelerinde ayarlanan algoritmaya bağlı olarak, olası şifreleme parametreleri kümesi değişir.

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);
encrypt(string, Uint8Array, EncryptOptions)

Belirtilen düz metni belirtilen şifreleme algoritmasıyla şifreler

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);
sign(string, Uint8Array, SignOptions)

İletinin özetini şifreli olarak imzalama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";
import { createHash } from "node:crypto";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

let myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const signatureValue = "MySignature";
const hash = createHash("sha256");

const digest = hash.update(signatureValue).digest();
console.log("digest: ", digest);

const signResult = await cryptographyClient.sign("RS256", digest);
console.log("sign result: ", signResult.result);
signData(string, Uint8Array, SignOptions)

Veri bloğunu kriptografik olarak imzalama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const signResult = await cryptographyClient.signData("RS256", Buffer.from("My Message"));
console.log("sign result: ", signResult.result);
unwrapKey(KeyWrapAlgorithm, Uint8Array, UnwrapKeyOptions)

Belirtilen şifreleme algoritmasını kullanarak verilen sarmalanmış anahtarın işaretini kaldırın

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const wrapResult = await cryptographyClient.wrapKey("RSA-OAEP", Buffer.from("My Key"));
console.log("wrap result:", wrapResult.result);

const unwrapResult = await cryptographyClient.unwrapKey("RSA-OAEP", wrapResult.result);
console.log("unwrap result: ", unwrapResult.result);
verify(string, Uint8Array, Uint8Array, VerifyOptions)

İmzalı ileti özetini doğrulama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";
import { createHash } from "node:crypto";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const hash = createHash("sha256");
hash.update("My Message");
const digest = hash.digest();

const signResult = await cryptographyClient.sign("RS256", digest);
console.log("sign result: ", signResult.result);

const verifyResult = await cryptographyClient.verify("RS256", digest, signResult.result);
console.log("verify result: ", verifyResult.result);
verifyData(string, Uint8Array, Uint8Array, VerifyOptions)

İmzalı veri bloğunu doğrulama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const buffer = Buffer.from("My Message");

const signResult = await cryptographyClient.signData("RS256", buffer);
console.log("sign result: ", signResult.result);

const verifyResult = await cryptographyClient.verifyData("RS256", buffer, signResult.result);
console.log("verify result: ", verifyResult.result);
wrapKey(KeyWrapAlgorithm, Uint8Array, WrapKeyOptions)

Belirtilen şifreleme algoritmasını kullanarak verilen anahtarı sarmalar

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const wrapResult = await cryptographyClient.wrapKey("RSA-OAEP", Buffer.from("My Key"));
console.log("wrap result:", wrapResult.result);

Oluşturucu Ayrıntıları

CryptographyClient(JsonWebKey)

Yerel modda verilen anahtar için Şifreleme istemcisinin yeni bir örneğini oluşturur.

Örnek kullanım:

import { CryptographyClient } from "@azure/keyvault-keys";

const jsonWebKey = {
  kty: "RSA",
  kid: "test-key-123",
  use: "sig",
  alg: "RS256",
  n: new Uint8Array([112, 34, 56, 98, 123, 244, 200, 99]),
  e: new Uint8Array([1, 0, 1]),
  d: new Uint8Array([45, 67, 89, 23, 144, 200, 76, 233]),
  p: new Uint8Array([34, 89, 100, 77, 204, 56, 29, 77]),
  q: new Uint8Array([78, 99, 201, 45, 188, 34, 67, 90]),
  dp: new Uint8Array([23, 45, 78, 56, 200, 144, 32, 67]),
  dq: new Uint8Array([12, 67, 89, 144, 99, 56, 23, 45]),
  qi: new Uint8Array([78, 90, 45, 201, 34, 67, 120, 55]),
};
const client = new CryptographyClient(jsonWebKey);
new CryptographyClient(key: JsonWebKey)

Parametreler

key
JsonWebKey

Şifreleme işlemleri sırasında kullanılacak JsonWebKey.

CryptographyClient(string | KeyVaultKey, TokenCredential, CryptographyClientOptions)

Verilen anahtar için Şifreleme istemcisinin yeni bir örneğini oluşturur

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

// Create or retrieve a key from the keyvault
const myKey = await client.createKey("MyKey", "RSA");

// Lastly, create our cryptography client and connect to the service
const cryptographyClient = new CryptographyClient(myKey, credential);
new CryptographyClient(key: string | KeyVaultKey, credential: TokenCredential, pipelineOptions?: CryptographyClientOptions)

Parametreler

key

string | KeyVaultKey

Şifreleme görevleri sırasında kullanılacak anahtar. Anahtarın tanımlayıcısını (url'si gibi) buradan da geçirebilirsiniz.

credential
TokenCredential

Hizmete yönelik isteklerin kimliğini doğrulamak için kullanılan TokenCredential arabirimini uygulayan nesne. gereksinimlerinize uygun bir kimlik bilgisi oluşturmak için @azure/identity paketini kullanın.

pipelineOptions
CryptographyClientOptions

Key Vault API isteklerini yapılandırmak için kullanılan işlem hattı seçenekleri. Varsayılan işlem hattı yapılandırmasını kullanmak için bu parametreyi atlayın.

Özellik Ayrıntıları

keyID

İstemci için şifreleme işlemleri gerçekleştirmek için kullanılan anahtarın kimliği.

undefined | string keyID

Özellik Değeri

undefined | string

vaultUrl

Kasanın temel URL'si. Yerel bir JsonWebKey kullanılırsa vaultUrl boş olur.

string vaultUrl

Özellik Değeri

string

Yöntem Ayrıntıları

decrypt(DecryptParameters, DecryptOptions)

Belirtilen şifre çözme parametreleriyle verilen şifreleme metninin şifresini çözer. Şifre çözme parametrelerinde kullanılan algoritmaya bağlı olarak, olası şifre çözme parametreleri kümesi değişir.

Microsoft, önce bir HMAC kullanarak şifre metninin bütünlüğünü sağlamadan CBC kullanmamanızı önerir. Daha fazla bilgi için bkz. https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode.

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);

const decryptResult = await cryptographyClient.decrypt({
  algorithm: "RSA1_5",
  ciphertext: encryptResult.result,
});
console.log("decrypt result: ", decryptResult.result.toString());
function decrypt(decryptParameters: DecryptParameters, options?: DecryptOptions): Promise<DecryptResult>

Parametreler

decryptParameters
DecryptParameters

Şifre çözme parametreleri.

options
DecryptOptions

Ek seçenekler.

Döndürülenler

Promise<DecryptResult>

decrypt(string, Uint8Array, DecryptOptions)

Uyarı

Bu API artık kullanım dışıdır.

Use decrypt({ algorithm, ciphertext }, options) instead.

Belirtilen şifreleme algoritmasıyla verilen şifreleme metninin şifresini çözer

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);

const decryptResult = await cryptographyClient.decrypt({
  algorithm: "RSA1_5",
  ciphertext: encryptResult.result,
});
console.log("decrypt result: ", decryptResult.result.toString());

Microsoft, önce bir HMAC kullanarak şifre metninin bütünlüğünü sağlamadan CBC kullanmamanızı önerir. Daha fazla bilgi için bkz. https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode.

function decrypt(algorithm: string, ciphertext: Uint8Array, options?: DecryptOptions): Promise<DecryptResult>

Parametreler

algorithm

string

Kullanılacak algoritma.

ciphertext

Uint8Array

Şifresi çözülecek metin.

options
DecryptOptions

Ek seçenekler.

Döndürülenler

Promise<DecryptResult>

encrypt(EncryptParameters, EncryptOptions)

Belirtilen düz metni belirtilen şifreleme parametreleriyle şifreler. Şifreleme parametrelerinde ayarlanan algoritmaya bağlı olarak, olası şifreleme parametreleri kümesi değişir.

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);
function encrypt(encryptParameters: EncryptParameters, options?: EncryptOptions): Promise<EncryptResult>

Parametreler

encryptParameters
EncryptParameters

Seçilen şifreleme algoritmasında anahtarlanan şifreleme parametreleri.

options
EncryptOptions

Ek seçenekler.

Döndürülenler

Promise<EncryptResult>

encrypt(string, Uint8Array, EncryptOptions)

Uyarı

Bu API artık kullanım dışıdır.

Use encrypt({ algorithm, plaintext }, options) instead.

Belirtilen düz metni belirtilen şifreleme algoritmasıyla şifreler

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey.id, credential);

const encryptResult = await cryptographyClient.encrypt({
  algorithm: "RSA1_5",
  plaintext: Buffer.from("My Message"),
});
console.log("encrypt result: ", encryptResult.result);
function encrypt(algorithm: string, plaintext: Uint8Array, options?: EncryptOptions): Promise<EncryptResult>

Parametreler

algorithm

string

Kullanılacak algoritma.

plaintext

Uint8Array

Şifrelenmesi gereken metin.

options
EncryptOptions

Ek seçenekler.

Döndürülenler

Promise<EncryptResult>

sign(string, Uint8Array, SignOptions)

İletinin özetini şifreli olarak imzalama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";
import { createHash } from "node:crypto";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

let myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const signatureValue = "MySignature";
const hash = createHash("sha256");

const digest = hash.update(signatureValue).digest();
console.log("digest: ", digest);

const signResult = await cryptographyClient.sign("RS256", digest);
console.log("sign result: ", signResult.result);
function sign(algorithm: string, digest: Uint8Array, options?: SignOptions): Promise<SignResult>

Parametreler

algorithm

string

Kullanılacak imzalama algoritması.

digest

Uint8Array

İmzalayacak verilerin özeti.

options
SignOptions

Ek seçenekler.

Döndürülenler

Promise<SignResult>

signData(string, Uint8Array, SignOptions)

Veri bloğunu kriptografik olarak imzalama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const signResult = await cryptographyClient.signData("RS256", Buffer.from("My Message"));
console.log("sign result: ", signResult.result);
function signData(algorithm: string, data: Uint8Array, options?: SignOptions): Promise<SignResult>

Parametreler

algorithm

string

Kullanılacak imzalama algoritması.

data

Uint8Array

İmzalayacak veriler.

options
SignOptions

Ek seçenekler.

Döndürülenler

Promise<SignResult>

unwrapKey(KeyWrapAlgorithm, Uint8Array, UnwrapKeyOptions)

Belirtilen şifreleme algoritmasını kullanarak verilen sarmalanmış anahtarın işaretini kaldırın

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const wrapResult = await cryptographyClient.wrapKey("RSA-OAEP", Buffer.from("My Key"));
console.log("wrap result:", wrapResult.result);

const unwrapResult = await cryptographyClient.unwrapKey("RSA-OAEP", wrapResult.result);
console.log("unwrap result: ", unwrapResult.result);
function unwrapKey(algorithm: KeyWrapAlgorithm, encryptedKey: Uint8Array, options?: UnwrapKeyOptions): Promise<UnwrapResult>

Parametreler

algorithm
KeyWrapAlgorithm

Anahtarı açmak için kullanılacak şifre çözme algoritması.

encryptedKey

Uint8Array

Çözülecek şifreli anahtar.

options
UnwrapKeyOptions

Ek seçenekler.

Döndürülenler

Promise<UnwrapResult>

verify(string, Uint8Array, Uint8Array, VerifyOptions)

İmzalı ileti özetini doğrulama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";
import { createHash } from "node:crypto";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const hash = createHash("sha256");
hash.update("My Message");
const digest = hash.digest();

const signResult = await cryptographyClient.sign("RS256", digest);
console.log("sign result: ", signResult.result);

const verifyResult = await cryptographyClient.verify("RS256", digest, signResult.result);
console.log("verify result: ", verifyResult.result);
function verify(algorithm: string, digest: Uint8Array, signature: Uint8Array, options?: VerifyOptions): Promise<VerifyResult>

Parametreler

algorithm

string

ile doğrulamak için kullanılacak imzalama algoritması.

digest

Uint8Array

Doğrulanması gereken özet.

signature

Uint8Array

Özetin doğrulanması için imza.

options
VerifyOptions

Ek seçenekler.

Döndürülenler

Promise<VerifyResult>

verifyData(string, Uint8Array, Uint8Array, VerifyOptions)

İmzalı veri bloğunu doğrulama

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const buffer = Buffer.from("My Message");

const signResult = await cryptographyClient.signData("RS256", buffer);
console.log("sign result: ", signResult.result);

const verifyResult = await cryptographyClient.verifyData("RS256", buffer, signResult.result);
console.log("verify result: ", verifyResult.result);
function verifyData(algorithm: string, data: Uint8Array, signature: Uint8Array, options?: VerifyOptions): Promise<VerifyResult>

Parametreler

algorithm

string

ile doğrulamak için kullanılacak algoritma.

data

Uint8Array

Doğrulanması gereken imzalı veri bloğu.

signature

Uint8Array

Bloğun doğrulanması için imza.

options
VerifyOptions

Ek seçenekler.

Döndürülenler

Promise<VerifyResult>

wrapKey(KeyWrapAlgorithm, Uint8Array, WrapKeyOptions)

Belirtilen şifreleme algoritmasını kullanarak verilen anahtarı sarmalar

Örnek kullanım:

import { DefaultAzureCredential } from "@azure/identity";
import { KeyClient, CryptographyClient } from "@azure/keyvault-keys";

const credential = new DefaultAzureCredential();

const vaultName = "<YOUR KEYVAULT NAME>";
const url = `https://${vaultName}.vault.azure.net`;

const client = new KeyClient(url, credential);

const myKey = await client.createKey("MyKey", "RSA");
const cryptographyClient = new CryptographyClient(myKey, credential);

const wrapResult = await cryptographyClient.wrapKey("RSA-OAEP", Buffer.from("My Key"));
console.log("wrap result:", wrapResult.result);
function wrapKey(algorithm: KeyWrapAlgorithm, key: Uint8Array, options?: WrapKeyOptions): Promise<WrapResult>

Parametreler

algorithm
KeyWrapAlgorithm

Verilen anahtarı sarmak için kullanılacak şifreleme algoritması.

key

Uint8Array

Sarmalama anahtarı.

options
WrapKeyOptions

Ek seçenekler.

Döndürülenler

Promise<WrapResult>