-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[KeyVault-Keys] The CryptographyClient indeed works with a KeyVaultKey #9647
Changes from 9 commits
24f4128
07127c4
04d548c
38390fa
7d7877e
d91c3af
e83c75d
b0d864f
fd9ba89
6edaafd
cde6f3c
24eef7a
2ee256d
97bd886
96d7219
a0d9c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import * as assert from "assert"; | ||
import { createHash, publicEncrypt } from "crypto"; | ||
import * as constants from "constants"; | ||
import { isRecordMode, Recorder } from "@azure/test-utils-recorder"; | ||
import { isRecordMode, Recorder, env } from "@azure/test-utils-recorder"; | ||
import { ClientSecretCredential } from "@azure/identity"; | ||
import { isNode } from "@azure/core-http"; | ||
|
||
|
@@ -15,6 +15,7 @@ import TestClient from "../utils/testClient"; | |
import { stringToUint8Array, uint8ArrayToString } from "../utils/crypto"; | ||
|
||
describe("CryptographyClient (all decrypts happen remotely)", () => { | ||
const keyPrefix = `crypto${env.KEY_NAME || "KeyName"}`; | ||
let client: KeyClient; | ||
let testClient: TestClient; | ||
let cryptoClient: CryptographyClient; | ||
|
@@ -83,6 +84,18 @@ describe("CryptographyClient (all decrypts happen remotely)", () => { | |
const decryptedText = uint8ArrayToString(decryptResult.result); | ||
assert.equal(text, decryptedText); | ||
}); | ||
|
||
it("the CryptographyClient can be created from a full KeyVaultKey object", async function() { | ||
const keyName = testClient.formatName(`${keyPrefix}-${this!.test!.title}-${keySuffix}`); | ||
const keyVaultKey = await client.createKey(keyName, "RSA"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other tests in this block use the key created in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to show that a new key with nothing special can be used to create this client. |
||
const cryptoClientFromKey = new CryptographyClient(keyVaultKey, credential); | ||
|
||
const text = this.test!.title; | ||
const encryptResult = await cryptoClientFromKey.encrypt("RSA1_5", stringToUint8Array(text)); | ||
const decryptResult = await cryptoClientFromKey.decrypt("RSA1_5", encryptResult.result); | ||
const decryptedText = uint8ArrayToString(decryptResult.result); | ||
assert.equal(text, decryptedText); | ||
}); | ||
} | ||
|
||
// Local encryption is only supported in NodeJS. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks weird, but it's just an alignment after the comment was moved from this parameter to the proper place in the constructor documentation.