Share via


CryptographyClient class

用來在 Azure 金鑰保存庫金鑰或本機 JsonWebKey上執行密碼編譯作業的用戶端。

建構函式

CryptographyClient(JsonWebKey_2)

在原生模式中,為指定的金鑰建構密碼編譯用戶端的新實例。

使用方式範例:

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

const jsonWebKey: JsonWebKey = {
  // ...
};
const client = new CryptographyClient(jsonWebKey);
CryptographyClient(string | KeyVaultKey, TokenCredential, CryptographyClientOptions)

為指定的金鑰建構密碼編譯用戶端的新實例

使用方式範例:

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

let vaultUrl = `https://<MY KEYVAULT HERE>.vault.azure.net`;
let credentials = new DefaultAzureCredential();

let keyClient = new KeyClient(vaultUrl, credentials);
let keyVaultKey = await keyClient.getKey("MyKey");

let client = new CryptographyClient(keyVaultKey.id, credentials);
// or
let client = new CryptographyClient(keyVaultKey, credentials);

屬性

keyID

用來執行用戶端密碼編譯作業之金鑰的識別碼。

vaultUrl

保存庫的基底 URL。 如果使用本機 JsonWebKey VaultUrl 將會是空的。

方法

decrypt(DecryptParameters, DecryptOptions)

使用指定的解密參數解密指定的加密文字。 根據解密參數中使用的演算法,可能的解密參數集將會變更。

Microsoft 建議您不要先使用 CBC,而不需要先確保使用加密文字的完整性,例如 HMAC。 如需相關資訊,請參閱 https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.decrypt({ algorithm: "RSA1_5", ciphertext: encryptedBuffer });
let result = await client.decrypt({ algorithm: "A256GCM", iv: ivFromEncryptResult, authenticationTag: tagFromEncryptResult });
decrypt(string, Uint8Array, DecryptOptions)

使用指定的密碼編譯演算法解密指定的加密文字

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.decrypt("RSA1_5", encryptedBuffer);

Microsoft 建議您不要先使用 CBC,而不需要先確保使用加密文字的完整性,例如 HMAC。 如需相關資訊,請參閱 https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode

encrypt(EncryptParameters, EncryptOptions)

使用指定的加密參數來加密指定的純文字。 根據加密參數中設定的演算法,可能加密參數的集合將會變更。

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.encrypt({ algorithm: "RSA1_5", plaintext: Buffer.from("My Message")});
let result = await client.encrypt({ algorithm: "A256GCM", plaintext: Buffer.from("My Message"), additionalAuthenticatedData: Buffer.from("My authenticated data")});
encrypt(string, Uint8Array, EncryptOptions)

使用指定的密碼編譯演算法加密指定的純文字

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.encrypt("RSA1_5", Buffer.from("My Message"));
sign(string, Uint8Array, SignOptions)

以密碼編譯方式簽署訊息的摘要

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.sign("RS256", digest);
signData(string, Uint8Array, SignOptions)

以密碼編譯方式簽署資料區塊

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.signData("RS256", message);
unwrapKey(KeyWrapAlgorithm, Uint8Array, UnwrapKeyOptions)

使用指定的密碼編譯演算法解除包裝指定的包裝金鑰

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.unwrapKey("RSA1_5", keyToUnwrap);
verify(string, Uint8Array, Uint8Array, VerifyOptions)

確認已簽署的訊息摘要

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.verify("RS256", signedDigest, signature);
verifyData(string, Uint8Array, Uint8Array, VerifyOptions)

確認已簽署的資料區塊

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.verifyData("RS256", signedMessage, signature);
wrapKey(KeyWrapAlgorithm, Uint8Array, WrapKeyOptions)

使用指定的密碼編譯演算法包裝指定的金鑰

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.wrapKey("RSA1_5", keyToWrap);

建構函式詳細資料

CryptographyClient(JsonWebKey_2)

在原生模式中,為指定的金鑰建構密碼編譯用戶端的新實例。

使用方式範例:

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

const jsonWebKey: JsonWebKey = {
  // ...
};
const client = new CryptographyClient(jsonWebKey);
new CryptographyClient(key: JsonWebKey_2)

參數

key
JsonWebKey

在密碼編譯作業期間要使用的 JsonWebKey。

CryptographyClient(string | KeyVaultKey, TokenCredential, CryptographyClientOptions)

為指定的金鑰建構密碼編譯用戶端的新實例

使用方式範例:

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

let vaultUrl = `https://<MY KEYVAULT HERE>.vault.azure.net`;
let credentials = new DefaultAzureCredential();

let keyClient = new KeyClient(vaultUrl, credentials);
let keyVaultKey = await keyClient.getKey("MyKey");

let client = new CryptographyClient(keyVaultKey.id, credentials);
// or
let client = new CryptographyClient(keyVaultKey, credentials);
new CryptographyClient(key: string | KeyVaultKey, credential: TokenCredential, pipelineOptions?: CryptographyClientOptions)

參數

key

string | KeyVaultKey

密碼編譯工作期間要使用的金鑰。 您也可以在這裡傳遞金鑰的識別碼,也就是其 URL。

credential
TokenCredential

實作 介面的物件, TokenCredential 用來驗證對服務的要求。 @azure/identity使用套件來建立符合您需求的認證。

pipelineOptions
CryptographyClientOptions

用來設定 金鑰保存庫 API 要求的管線選項。 省略此參數以使用預設管線組態。

屬性詳細資料

keyID

用來執行用戶端密碼編譯作業之金鑰的識別碼。

undefined | string keyID

屬性值

undefined | string

vaultUrl

保存庫的基底 URL。 如果使用本機 JsonWebKey VaultUrl 將會是空的。

string vaultUrl

屬性值

string

方法詳細資料

decrypt(DecryptParameters, DecryptOptions)

使用指定的解密參數解密指定的加密文字。 根據解密參數中使用的演算法,可能的解密參數集將會變更。

Microsoft 建議您不要先使用 CBC,而不需要先確保使用加密文字的完整性,例如 HMAC。 如需相關資訊,請參閱 https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.decrypt({ algorithm: "RSA1_5", ciphertext: encryptedBuffer });
let result = await client.decrypt({ algorithm: "A256GCM", iv: ivFromEncryptResult, authenticationTag: tagFromEncryptResult });
function decrypt(decryptParameters: DecryptParameters, options?: DecryptOptions): Promise<DecryptResult>

參數

decryptParameters
DecryptParameters

解密參數。

options
DecryptOptions

其他選項。

傳回

Promise<DecryptResult>

decrypt(string, Uint8Array, DecryptOptions)

警告

此 API 現已淘汰。

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

使用指定的密碼編譯演算法解密指定的加密文字

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.decrypt("RSA1_5", encryptedBuffer);

Microsoft 建議您不要先使用 CBC,而不需要先確保使用加密文字的完整性,例如 HMAC。 如需相關資訊,請參閱 https://docs.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode

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

參數

algorithm

string

要使用的演算法。

ciphertext

Uint8Array

要解密的文字。

options
DecryptOptions

其他選項。

傳回

Promise<DecryptResult>

encrypt(EncryptParameters, EncryptOptions)

使用指定的加密參數來加密指定的純文字。 根據加密參數中設定的演算法,可能加密參數的集合將會變更。

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.encrypt({ algorithm: "RSA1_5", plaintext: Buffer.from("My Message")});
let result = await client.encrypt({ algorithm: "A256GCM", plaintext: Buffer.from("My Message"), additionalAuthenticatedData: Buffer.from("My authenticated data")});
function encrypt(encryptParameters: EncryptParameters, options?: EncryptOptions): Promise<EncryptResult>

參數

encryptParameters
EncryptParameters

加密參數,以所選的加密演算法為金鑰。

options
EncryptOptions

其他選項。

傳回

Promise<EncryptResult>

encrypt(string, Uint8Array, EncryptOptions)

警告

此 API 現已淘汰。

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

使用指定的密碼編譯演算法加密指定的純文字

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.encrypt("RSA1_5", Buffer.from("My Message"));
function encrypt(algorithm: string, plaintext: Uint8Array, options?: EncryptOptions): Promise<EncryptResult>

參數

algorithm

string

要使用的演算法。

plaintext

Uint8Array

要加密的文字。

options
EncryptOptions

其他選項。

傳回

Promise<EncryptResult>

sign(string, Uint8Array, SignOptions)

以密碼編譯方式簽署訊息的摘要

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.sign("RS256", digest);
function sign(algorithm: string, digest: Uint8Array, options?: SignOptions): Promise<SignResult>

參數

algorithm

string

要使用的簽署演算法。

digest

Uint8Array

要簽署之資料的摘要。

options
SignOptions

其他選項。

傳回

Promise<SignResult>

signData(string, Uint8Array, SignOptions)

以密碼編譯方式簽署資料區塊

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.signData("RS256", message);
function signData(algorithm: string, data: Uint8Array, options?: SignOptions): Promise<SignResult>

參數

algorithm

string

要使用的簽署演算法。

data

Uint8Array

要簽署的資料。

options
SignOptions

其他選項。

傳回

Promise<SignResult>

unwrapKey(KeyWrapAlgorithm, Uint8Array, UnwrapKeyOptions)

使用指定的密碼編譯演算法解除包裝指定的包裝金鑰

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.unwrapKey("RSA1_5", keyToUnwrap);
function unwrapKey(algorithm: KeyWrapAlgorithm, encryptedKey: Uint8Array, options?: UnwrapKeyOptions): Promise<UnwrapResult>

參數

algorithm
KeyWrapAlgorithm

用來解除包裝金鑰的解密演算法。

encryptedKey

Uint8Array

要解除包裝的加密金鑰。

options
UnwrapKeyOptions

其他選項。

傳回

Promise<UnwrapResult>

verify(string, Uint8Array, Uint8Array, VerifyOptions)

確認已簽署的訊息摘要

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.verify("RS256", signedDigest, signature);
function verify(algorithm: string, digest: Uint8Array, signature: Uint8Array, options?: VerifyOptions): Promise<VerifyResult>

參數

algorithm

string

要用來驗證的簽署演算法。

digest

Uint8Array

要驗證的摘要。

signature

Uint8Array

要驗證摘要的簽章。

options
VerifyOptions

其他選項。

傳回

Promise<VerifyResult>

verifyData(string, Uint8Array, Uint8Array, VerifyOptions)

確認已簽署的資料區塊

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.verifyData("RS256", signedMessage, signature);
function verifyData(algorithm: string, data: Uint8Array, signature: Uint8Array, options?: VerifyOptions): Promise<VerifyResult>

參數

algorithm

string

用來驗證的演算法。

data

Uint8Array

要驗證之已簽署的資料區塊。

signature

Uint8Array

要驗證區塊的簽章。

options
VerifyOptions

其他選項。

傳回

Promise<VerifyResult>

wrapKey(KeyWrapAlgorithm, Uint8Array, WrapKeyOptions)

使用指定的密碼編譯演算法包裝指定的金鑰

使用方式範例:

let client = new CryptographyClient(keyVaultKey, credentials);
let result = await client.wrapKey("RSA1_5", keyToWrap);
function wrapKey(algorithm: KeyWrapAlgorithm, key: Uint8Array, options?: WrapKeyOptions): Promise<WrapResult>

參數

algorithm
KeyWrapAlgorithm

用來包裝指定金鑰的加密演算法。

key

Uint8Array

要包裝的索引鍵。

options
WrapKeyOptions

其他選項。

傳回

Promise<WrapResult>