SqlAes256CbcAlgorithm.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //------------------------------------------------------------------------------
  2. // <copyright file="SqlAes256CbcAlgorithm.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">balnee</owner>
  6. // <owner current="true" primary="false">krishnib</owner>
  7. //------------------------------------------------------------------------------
  8. namespace System.Data.SqlClient
  9. {
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data.SqlClient;
  13. using System.Diagnostics;
  14. using System.IO;
  15. using System.Runtime.CompilerServices;
  16. using System.Security.Cryptography;
  17. /// <summary>
  18. /// This class implements AES_256_CBC algorithm.
  19. /// </summary>
  20. internal class SqlAes256CbcAlgorithm : SqlAeadAes256CbcHmac256Algorithm
  21. {
  22. /// <summary>
  23. /// Algorithm Name
  24. /// </summary>
  25. internal new const string AlgorithmName = @"AES_256_CBC";
  26. /// <summary>
  27. /// Initializes a new instance of SqlAes256CbcAlgorithm algorithm with a given key and encryption type
  28. /// </summary>
  29. /// <param name="encryptionKey">
  30. /// Root encryption key from which three other keys will be derived
  31. /// </param>
  32. /// <param name="encryptionType">Encryption Type, accepted values are Deterministic and Randomized.
  33. /// For Deterministic encryption, a synthetic IV will be genenrated during encryption
  34. /// For Randomized encryption, a random IV will be generated during encryption.
  35. /// </param>
  36. /// <param name="algorithmVersion">
  37. /// Algorithm version
  38. /// </param>
  39. internal SqlAes256CbcAlgorithm(SqlAeadAes256CbcHmac256EncryptionKey encryptionKey, SqlClientEncryptionType encryptionType, byte algorithmVersion)
  40. :base(encryptionKey, encryptionType, algorithmVersion)
  41. { }
  42. /// <summary>
  43. /// Encryption Algorithm
  44. /// Simply call the base class, indicating we don't need an authentication tag.
  45. /// </summary>
  46. /// <param name="plainText">Plaintext data to be encrypted</param>
  47. /// <returns>Returns the ciphertext corresponding to the plaintext.</returns>
  48. internal override byte[] EncryptData(byte[] plainText) {
  49. return EncryptData(plainText, hasAuthenticationTag: false);
  50. }
  51. /// <summary>
  52. /// Decryption Algorithm
  53. /// Simply call the base class, indicating we don't have an authentication tag.
  54. /// </summary>
  55. /// <param name="cipherText"></param>
  56. /// <returns></returns>
  57. internal override byte[] DecryptData(byte[] cipherText) {
  58. return base.DecryptData(cipherText, hasAuthenticationTag: false);
  59. }
  60. }
  61. }