你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CryptographyClient class

用于对 Azure Key Vault 密钥或本地 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

用于为客户端执行加密操作的密钥的 ID。

vaultUrl

保管库的基 URL。 如果使用本地 JsonWebKey ,vaultUrl 将为空。

方法

decrypt(DecryptParameters, DecryptOptions)

使用指定的解密参数解密给定的密码文本。 根据解密参数中使用的算法,可能的解密参数集将更改。

Microsoft 建议不要在未首先使用 HMAC(例如 HMAC)确保密文完整性的情况下使用 CBC。 有关详细信息,请参阅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 建议不要在未首先使用 HMAC(例如 HMAC)确保密文完整性的情况下使用 CBC。 有关详细信息,请参阅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

用于为客户端执行加密操作的密钥的 ID。

undefined | string keyID

属性值

undefined | string

vaultUrl

保管库的基 URL。 如果使用本地 JsonWebKey ,vaultUrl 将为空。

string vaultUrl

属性值

string

方法详细信息

decrypt(DecryptParameters, DecryptOptions)

使用指定的解密参数解密给定的密码文本。 根据解密参数中使用的算法,可能的解密参数集将更改。

Microsoft 建议不要在未首先使用 HMAC(例如 HMAC)确保密文完整性的情况下使用 CBC。 有关详细信息,请参阅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 建议不要在未首先使用 HMAC(例如 HMAC)确保密文完整性的情况下使用 CBC。 有关详细信息,请参阅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>