CryptographyClient class
Azure Key Vault キーまたはローカル JsonWebKeyに対して暗号化操作を実行するために使用されるクライアント。
コンストラクター
Cryptography |
指定されたキーの暗号化クライアントの新しいインスタンスをローカル モードで構築します。 使用例:
|
Cryptography |
指定されたキーの Cryptography クライアントの新しいインスタンスを構築します 使用例:
|
プロパティ
keyID | クライアントの暗号化操作を実行するために使用されるキーの ID。 |
vault |
コンテナーへのベース URL。 ローカル JsonWebKey が使用されている場合、vaultUrl は空になります。 |
メソッド
decrypt(Decrypt |
指定した暗号化解除パラメーターを使用して、指定された暗号テキストを復号化します。 復号化パラメーターで使用されるアルゴリズムに応じて、可能な復号化パラメーターのセットが変更されます。 Microsoft では、HMAC などを使用して暗号テキストの整合性を最初に確認せずに CBC を使用しないことをお勧めします。 詳細については、https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode を参照してください。 使用例:
|
decrypt(string, Uint8Array, Decrypt |
指定した暗号アルゴリズムを使用して、指定された暗号テキストを復号化します 使用例:
Microsoft では、HMAC などを使用して暗号テキストの整合性を最初に確認せずに CBC を使用しないことをお勧めします。 詳細については、https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode を参照してください。 |
encrypt(Encrypt |
指定した暗号化パラメーターを使用して、指定されたプレーンテキストを暗号化します。 暗号化パラメーターに設定されているアルゴリズムに応じて、使用可能な暗号化パラメーターのセットが変更されます。 使用例:
|
encrypt(string, Uint8Array, Encrypt |
指定された暗号化アルゴリズムを使用して、指定されたプレーンテキストを暗号化します 使用例:
|
sign(string, Uint8Array, Sign |
メッセージのダイジェストに暗号で署名する 使用例:
|
sign |
データブロックに暗号で署名する 使用例:
|
unwrap |
指定した暗号化アルゴリズムを使用して、指定されたラップされたキーのラップを解除します 使用例:
|
verify(string, Uint8Array, Uint8Array, Verify |
署名されたメッセージ ダイジェストを確認する 使用例:
|
verify |
署名されたデータ ブロックを確認する 使用例:
|
wrap |
指定した暗号化アルゴリズムを使用して、指定されたキーをラップします。 使用例:
|
コンストラクターの詳細
CryptographyClient(JsonWebKey)
指定されたキーの暗号化クライアントの新しいインスタンスをローカル モードで構築します。
使用例:
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)
パラメーター
- key
- JsonWebKey
暗号化操作中に使用する JsonWebKey。
CryptographyClient(string | KeyVaultKey, TokenCredential, CryptographyClientOptions)
指定されたキーの Cryptography クライアントの新しいインスタンスを構築します
使用例:
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)
パラメーター
- key
-
string | KeyVaultKey
暗号化タスク中に使用するキー。 キーの識別子 (URL) をここで渡すこともできます。
- credential
- TokenCredential
サービスへの要求を認証するために使用する TokenCredential
インターフェイスを実装するオブジェクト。
@azure/identity パッケージを使用して、ニーズに合った資格情報を作成します。
- pipelineOptions
- CryptographyClientOptions
Key Vault API 要求の構成に使用されるパイプライン オプション。 既定のパイプライン構成を使用するには、このパラメーターを省略します。
プロパティの詳細
keyID
クライアントの暗号化操作を実行するために使用されるキーの ID。
undefined | string keyID
プロパティ値
undefined | string
vaultUrl
メソッドの詳細
decrypt(DecryptParameters, DecryptOptions)
指定した暗号化解除パラメーターを使用して、指定された暗号テキストを復号化します。 復号化パラメーターで使用されるアルゴリズムに応じて、可能な復号化パラメーターのセットが変更されます。
Microsoft では、HMAC などを使用して暗号テキストの整合性を最初に確認せずに CBC を使用しないことをお勧めします。 詳細については、https://learn.microsoft.com/dotnet/standard/security/vulnerabilities-cbc-mode を参照してください。
使用例:
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>
パラメーター
- decryptParameters
- DecryptParameters
復号化パラメーター。
- options
- DecryptOptions
その他のオプション。
戻り値
Promise<DecryptResult>
decrypt(string, Uint8Array, DecryptOptions)
警告
この API は非推奨になりました。
Use decrypt({ algorithm, ciphertext }, options)
instead.
指定した暗号アルゴリズムを使用して、指定された暗号テキストを復号化します
使用例:
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 では、HMAC などを使用して暗号テキストの整合性を最初に確認せずに CBC を使用しないことをお勧めします。 詳細については、https://learn.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)
指定した暗号化パラメーターを使用して、指定されたプレーンテキストを暗号化します。 暗号化パラメーターに設定されているアルゴリズムに応じて、使用可能な暗号化パラメーターのセットが変更されます。
使用例:
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>
パラメーター
- encryptParameters
- EncryptParameters
選択した暗号化アルゴリズムに基づく暗号化パラメーター。
- options
- EncryptOptions
その他のオプション。
戻り値
Promise<EncryptResult>
encrypt(string, Uint8Array, EncryptOptions)
警告
この API は非推奨になりました。
Use encrypt({ algorithm, plaintext }, options)
instead.
指定された暗号化アルゴリズムを使用して、指定されたプレーンテキストを暗号化します
使用例:
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>
パラメーター
- algorithm
-
string
使用するアルゴリズム。
- plaintext
-
Uint8Array
暗号化するテキスト。
- options
- EncryptOptions
その他のオプション。
戻り値
Promise<EncryptResult>
sign(string, Uint8Array, SignOptions)
メッセージのダイジェストに暗号で署名する
使用例:
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>
パラメーター
- algorithm
-
string
使用する署名アルゴリズム。
- digest
-
Uint8Array
署名するデータのダイジェスト。
- options
- SignOptions
その他のオプション。
戻り値
Promise<SignResult>
signData(string, Uint8Array, SignOptions)
データブロックに暗号で署名する
使用例:
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>
パラメーター
- algorithm
-
string
使用する署名アルゴリズム。
- data
-
Uint8Array
署名するデータ。
- options
- SignOptions
その他のオプション。
戻り値
Promise<SignResult>
unwrapKey(KeyWrapAlgorithm, Uint8Array, UnwrapKeyOptions)
指定した暗号化アルゴリズムを使用して、指定されたラップされたキーのラップを解除します
使用例:
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>
パラメーター
- algorithm
- KeyWrapAlgorithm
キーのラップ解除に使用する復号化アルゴリズム。
- encryptedKey
-
Uint8Array
ラップを解除する暗号化されたキー。
- options
- UnwrapKeyOptions
その他のオプション。
戻り値
Promise<UnwrapResult>
verify(string, Uint8Array, Uint8Array, VerifyOptions)
署名されたメッセージ ダイジェストを確認する
使用例:
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>
パラメーター
- algorithm
-
string
検証に使用する署名アルゴリズム。
- digest
-
Uint8Array
確認するダイジェスト。
- signature
-
Uint8Array
ダイジェストを検証する署名。
- options
- VerifyOptions
その他のオプション。
戻り値
Promise<VerifyResult>
verifyData(string, Uint8Array, Uint8Array, VerifyOptions)
署名されたデータ ブロックを確認する
使用例:
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>
パラメーター
- algorithm
-
string
検証に使用するアルゴリズム。
- data
-
Uint8Array
検証するデータの符号付きブロック。
- signature
-
Uint8Array
ブロックを検証する対象の署名。
- options
- VerifyOptions
その他のオプション。
戻り値
Promise<VerifyResult>
wrapKey(KeyWrapAlgorithm, Uint8Array, WrapKeyOptions)
指定した暗号化アルゴリズムを使用して、指定されたキーをラップします。
使用例:
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>
パラメーター
- algorithm
- KeyWrapAlgorithm
指定されたキーをラップするために使用する暗号化アルゴリズム。
- key
-
Uint8Array
ラップするキー。
- options
- WrapKeyOptions
その他のオプション。
戻り値
Promise<WrapResult>