Skip to content

Commit

Permalink
update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
maorleger committed Feb 1, 2025
1 parent 16dc131 commit a7b293a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 51 deletions.
9 changes: 6 additions & 3 deletions sdk/keyvault/keyvault-keys/samples-dev/cryptography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ export async function main(): Promise<void> {
});
console.log("encrypt result: ", encrypt);

const decrypt = await cryptoClient.decrypt({ algorithm: "RSA1_5", ciphertext: encrypt.result });
const decrypt = await cryptoClient.decrypt({
algorithm: "RSA-OAEP-256",
ciphertext: encrypt.result,
});
console.log("decrypt: ", decrypt.result.toString());

// Wrap and unwrap
const wrapped = await cryptoClient.wrapKey("RSA-OAEP", Buffer.from("My Message"));
const wrapped = await cryptoClient.wrapKey("RSA-OAEP-256", Buffer.from("My Message"));
console.log("wrap result: ", wrapped);

const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP", wrapped.result);
const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP-256", wrapped.result);
console.log("unwrap result: ", unwrapped);
}

Expand Down
11 changes: 7 additions & 4 deletions sdk/keyvault/keyvault-keys/samples/v4/javascript/cryptography.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @summary Uses an Azure Key Vault key to sign/verify, encrypt/decrypt, and wrap/unwrap data.
*/

const { createHash } = require("crypto");
const { createHash } = require("node:crypto");

const { CryptographyClient, KeyClient } = require("@azure/keyvault-keys");
const { DefaultAzureCredential } = require("@azure/identity");
Expand Down Expand Up @@ -55,14 +55,17 @@ async function main() {
});
console.log("encrypt result: ", encrypt);

const decrypt = await cryptoClient.decrypt({ algorithm: "RSA1_5", ciphertext: encrypt.result });
const decrypt = await cryptoClient.decrypt({
algorithm: "RSA-OAEP-256",
ciphertext: encrypt.result,
});
console.log("decrypt: ", decrypt.result.toString());

// Wrap and unwrap
const wrapped = await cryptoClient.wrapKey("RSA-OAEP", Buffer.from("My Message"));
const wrapped = await cryptoClient.wrapKey("RSA-OAEP-256", Buffer.from("My Message"));
console.log("wrap result: ", wrapped);

const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP", wrapped.result);
const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP-256", wrapped.result);
console.log("unwrap result: ", unwrapped);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @summary Uses an Azure Key Vault key to sign/verify, encrypt/decrypt, and wrap/unwrap data.
*/

import { createHash } from "crypto";
import { createHash } from "node:crypto";

import { CryptographyClient, KeyClient } from "@azure/keyvault-keys";
import { DefaultAzureCredential } from "@azure/identity";
Expand Down Expand Up @@ -56,14 +56,17 @@ export async function main(): Promise<void> {
});
console.log("encrypt result: ", encrypt);

const decrypt = await cryptoClient.decrypt({ algorithm: "RSA1_5", ciphertext: encrypt.result });
const decrypt = await cryptoClient.decrypt({
algorithm: "RSA-OAEP-256",
ciphertext: encrypt.result,
});
console.log("decrypt: ", decrypt.result.toString());

// Wrap and unwrap
const wrapped = await cryptoClient.wrapKey("RSA-OAEP", Buffer.from("My Message"));
const wrapped = await cryptoClient.wrapKey("RSA-OAEP-256", Buffer.from("My Message"));
console.log("wrap result: ", wrapped);

const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP", wrapped.result);
const unwrapped = await cryptoClient.unwrapKey("RSA-OAEP-256", wrapped.result);
console.log("unwrap result: ", unwrapped);
}

Expand Down
36 changes: 2 additions & 34 deletions sdk/keyvault/keyvault-keys/src/cryptographyClientModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,19 @@ import {
JsonWebKeyCurveName as KeyCurveName,
KnownJsonWebKeyCurveName as KnownKeyCurveNames,
KnownJsonWebKeySignatureAlgorithm as KnownSignatureAlgorithms,
KnownJsonWebKeyEncryptionAlgorithm as KnownEncryptionAlgorithms,
JsonWebKeySignatureAlgorithm as SignatureAlgorithm,
} from "./generated/models/index.js";

export {
KeyCurveName,
EncryptionAlgorithm,
KnownEncryptionAlgorithms,
SignatureAlgorithm,
KnownKeyCurveNames,
KnownSignatureAlgorithms,
};

/** Known values of {@link EncryptionAlgorithm} that the service accepts. */
export enum KnownEncryptionAlgorithms {
/** Encryption Algorithm - RSA-OAEP */
RSAOaep = "RSA-OAEP",
/** Encryption Algorithm - RSA-OAEP-256 */
RSAOaep256 = "RSA-OAEP-256",
/** Encryption Algorithm - RSA1_5 */
RSA15 = "RSA1_5",
/** Encryption Algorithm - A128GCM */
A128GCM = "A128GCM",
/** Encryption Algorithm - A192GCM */
A192GCM = "A192GCM",
/** Encryption Algorithm - A256GCM */
A256GCM = "A256GCM",
/** Encryption Algorithm - A128KW */
A128KW = "A128KW",
/** Encryption Algorithm - A192KW */
A192KW = "A192KW",
/** Encryption Algorithm - A256KW */
A256KW = "A256KW",
/** Encryption Algorithm - A128CBC */
A128CBC = "A128CBC",
/** Encryption Algorithm - A192CBC */
A192CBC = "A192CBC",
/** Encryption Algorithm - A256CBC */
A256CBC = "A256CBC",
/** Encryption Algorithm - A128CBCPAD */
A128Cbcpad = "A128CBCPAD",
/** Encryption Algorithm - A192CBCPAD */
A192Cbcpad = "A192CBCPAD",
/** Encryption Algorithm - A256CBCPAD */
A256Cbcpad = "A256CBCPAD",
}

/**
* Supported algorithms for key wrapping/unwrapping
*/
Expand Down
6 changes: 0 additions & 6 deletions sdk/keyvault/keyvault-keys/src/generated/models/models.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7b293a

Please sign in to comment.