AesManaged.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // System.Security.Cryptography.AesManaged.cs
  3. //
  4. // Authors:
  5. // Mark Crichton ([email protected])
  6. // Andrew Birkett ([email protected])
  7. // Sebastien Pouliot ([email protected])
  8. // Kazuki Oikawa ([email protected])
  9. //
  10. // (C) 2002
  11. // Portions (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  12. // Copyright (C) 2004-2005,2008 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.Security.Permissions;
  34. using Mono.Security.Cryptography;
  35. namespace System.Security.Cryptography {
  36. // References:
  37. // a. FIPS PUB 197: Advanced Encryption Standard
  38. // http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
  39. // b. Aes Specification
  40. // http://csrc.nist.gov/CryptoToolkit/aes/Aes/Aes-ammended.pdf
  41. [HostProtection (SecurityAction.LinkDemand, MayLeakOnAbort=true)]
  42. public sealed class AesManaged : Aes {
  43. public AesManaged ()
  44. {
  45. }
  46. public override void GenerateIV ()
  47. {
  48. IVValue = KeyBuilder.IV (BlockSizeValue >> 3);
  49. }
  50. public override void GenerateKey ()
  51. {
  52. KeyValue = KeyBuilder.Key (KeySizeValue >> 3);
  53. }
  54. public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV)
  55. {
  56. return new AesTransform (this, false, rgbKey, rgbIV);
  57. }
  58. public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV)
  59. {
  60. return new AesTransform (this, true, rgbKey, rgbIV);
  61. }
  62. // I suppose some attributes differs ?!? because this does not look required
  63. public override byte[] IV {
  64. get { return base.IV; }
  65. set { base.IV = value; }
  66. }
  67. public override byte[] Key {
  68. get { return base.Key; }
  69. set { base.Key = value; }
  70. }
  71. public override int KeySize {
  72. get { return base.KeySize; }
  73. set { base.KeySize = value; }
  74. }
  75. #if false
  76. public override int FeedbackSize {
  77. get { return base.FeedbackSize; }
  78. set { base.FeedbackSize = value; }
  79. }
  80. public override CipherMode Mode {
  81. get { return base.CipherMode; }
  82. set { base.CipherMode = value; }
  83. }
  84. public override PaddingMode Padding {
  85. get { return base.PaddingMode; }
  86. set { base.PaddingMode = value; }
  87. }
  88. #endif
  89. public override ICryptoTransform CreateDecryptor ()
  90. {
  91. return CreateDecryptor (Key, IV);
  92. }
  93. public override ICryptoTransform CreateEncryptor()
  94. {
  95. return CreateEncryptor (Key, IV);
  96. }
  97. protected override void Dispose (bool disposing)
  98. {
  99. base.Dispose (disposing);
  100. }
  101. }
  102. }