-
Notifications
You must be signed in to change notification settings - Fork 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
Added support for encryption algorithms for symmetric keys #17209
Changes from 8 commits
2514dd1
c48a75a
7d030d0
67e837c
17b8e1b
37d0e65
059c29c
df0aeb7
596d98e
8b93751
b1f1511
ff77ba1
53c8771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes128CbcPad extends AesCbcPad { | ||
private static final int KEY_SIZE = 128; | ||
public static final String ALGORITHM_NAME = "A128CBCPAD"; | ||
|
||
Aes128CbcPad() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes128Gcm extends AesGcm { | ||
private static final int KEY_SIZE = 128; | ||
public static final String ALGORITHM_NAME = "A128GCM"; | ||
|
||
Aes128Gcm() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes192CbcPad extends AesCbcPad { | ||
private static final int KEY_SIZE = 192; | ||
public static final String ALGORITHM_NAME = "A192CBCPAD"; | ||
|
||
Aes192CbcPad() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes192Gcm extends AesGcm { | ||
private static final int KEY_SIZE = 192; | ||
public static final String ALGORITHM_NAME = "A192GCM"; | ||
|
||
Aes192Gcm() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes256CbcPad extends AesCbcPad { | ||
private static final int KEY_SIZE = 256; | ||
public static final String ALGORITHM_NAME = "A256CBCPAD"; | ||
|
||
Aes256CbcPad() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
class Aes256Gcm extends AesGcm { | ||
private static final int KEY_SIZE = 256; | ||
public static final String ALGORITHM_NAME = "A256GCM"; | ||
|
||
Aes256Gcm() { | ||
super(ALGORITHM_NAME, KEY_SIZE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
/** | ||
* A class containing configuration parameters that can be applied when decrypting AES-CBC keys with and without | ||
* padding. | ||
*/ | ||
public class AesCbcDecryptOptions extends DecryptOptions { | ||
/** | ||
* Creates an instance of {@link AesCbcDecryptOptions} with the given parameters. | ||
* | ||
* @param iv Initialization vector for the decryption operation. | ||
*/ | ||
public AesCbcDecryptOptions(byte[] iv) { | ||
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. Do you think these will be discoverable? In .NET, we waffled on classes like this vs. factories and opted for the latter for discoverability. Would htat work better here. You could, for example, mix that and builders by having a factory returning the right class that you can then set options, e.t.: EncryptOptions
.createA128GcmOptions(iv, key)
.setAdditionalAuthenticationData(data); I'm also wondering how they specify the key size with this. 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. The Key size is specified in the clients. For example: CryptographyClient.encrypt(EncryptionAlgorithm algorithm, String plaintext, EncryptOptions options) 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. Do you have any thoughts on this @srnagar, @JonathanGiles? 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. Since these are inputs to the API, how does the user know what are the available subtypes of EncryptOptions/DecryptOptions. In other places, we have used a type flag to switch between strongly typed sub-classes. |
||
super(iv, null, null); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.security.keyvault.keys.cryptography; | ||
|
||
/** | ||
* A class containing configuration parameters that can be applied when encrypting AES-CBC keys with and without | ||
* padding. | ||
*/ | ||
public class AesCbcEncryptOptions extends EncryptOptions { | ||
/** | ||
* Creates an instance of {@link AesCbcEncryptOptions} with the given parameters. | ||
* | ||
* @param iv Initialization vector for the encryption operation. | ||
*/ | ||
public AesCbcEncryptOptions(byte[] iv) { | ||
super(iv, null); | ||
} | ||
} |
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.
@lusitanian should this be zero-padding? When we spoke about .NET, you said zero-padding was what the service was using.
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.
...if this is right, I'll have to change .NET's implementation to NoPadding as well.
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.
Going from the name only it made sense to me that we should not use padding for AES-CBC and use padding for AES-CBC-PAD. Is that not the case?
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.
When I asked MHSM about it, the reply was that zero-padding seems to be closer. I'm honestly not sure. If you're writing tests, maybe try it against the service and see what it does with CBC vs CBCPAD.