Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / BCL / System / Security / Cryptography / RijndaelManaged.cs / 1 / RijndaelManaged.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// RijndaelManaged.cs
//
namespace System.Security.Cryptography
{
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RijndaelManaged : Rijndael {
public RijndaelManaged () {
if (Utils.FipsAlgorithmPolicy == 1)
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
}
public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) {
return NewEncryptor (rgbKey, ModeValue, rgbIV, FeedbackSizeValue, RijndaelManagedTransformMode.Encrypt);
}
public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) {
return NewEncryptor (rgbKey, ModeValue, rgbIV, FeedbackSizeValue, RijndaelManagedTransformMode.Decrypt);
}
public override void GenerateKey () {
KeyValue = new byte[KeySizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(KeyValue);
}
public override void GenerateIV () {
IVValue = new byte[BlockSizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(IVValue);
}
private ICryptoTransform NewEncryptor (byte[] rgbKey,
CipherMode mode,
byte[] rgbIV,
int feedbackSize,
RijndaelManagedTransformMode encryptMode) {
// Build the key if one does not already exist
if (rgbKey == null) {
rgbKey = new byte[KeySizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
}
// If not ECB mode, make sure we have an IV
if (mode != CipherMode.ECB) {
if (rgbIV == null) {
rgbIV = new byte[BlockSizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
}
}
// Create the encryptor/decryptor object
return new RijndaelManagedTransform (rgbKey,
mode,
rgbIV,
BlockSizeValue,
feedbackSize,
PaddingValue,
encryptMode);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// RijndaelManaged.cs
//
namespace System.Security.Cryptography
{
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RijndaelManaged : Rijndael {
public RijndaelManaged () {
if (Utils.FipsAlgorithmPolicy == 1)
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
}
public override ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV) {
return NewEncryptor (rgbKey, ModeValue, rgbIV, FeedbackSizeValue, RijndaelManagedTransformMode.Encrypt);
}
public override ICryptoTransform CreateDecryptor (byte[] rgbKey, byte[] rgbIV) {
return NewEncryptor (rgbKey, ModeValue, rgbIV, FeedbackSizeValue, RijndaelManagedTransformMode.Decrypt);
}
public override void GenerateKey () {
KeyValue = new byte[KeySizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(KeyValue);
}
public override void GenerateIV () {
IVValue = new byte[BlockSizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(IVValue);
}
private ICryptoTransform NewEncryptor (byte[] rgbKey,
CipherMode mode,
byte[] rgbIV,
int feedbackSize,
RijndaelManagedTransformMode encryptMode) {
// Build the key if one does not already exist
if (rgbKey == null) {
rgbKey = new byte[KeySizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(rgbKey);
}
// If not ECB mode, make sure we have an IV
if (mode != CipherMode.ECB) {
if (rgbIV == null) {
rgbIV = new byte[BlockSizeValue/8];
Utils.StaticRandomNumberGenerator.GetBytes(rgbIV);
}
}
// Create the encryptor/decryptor object
return new RijndaelManagedTransform (rgbKey,
mode,
rgbIV,
BlockSizeValue,
feedbackSize,
PaddingValue,
encryptMode);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FixedTextView.cs
- Stack.cs
- ControlParameter.cs
- FlowLayoutPanelDesigner.cs
- SqlNotificationRequest.cs
- ItemList.cs
- GradientStopCollection.cs
- RSAOAEPKeyExchangeFormatter.cs
- HtmlToClrEventProxy.cs
- PersonalizationDictionary.cs
- TagPrefixAttribute.cs
- MsiStyleLogWriter.cs
- JobStaple.cs
- DataFieldEditor.cs
- TdsParserStateObject.cs
- UnsafeMethods.cs
- DataTableTypeConverter.cs
- DocumentReferenceCollection.cs
- BitmapEffectCollection.cs
- Psha1DerivedKeyGenerator.cs
- WSTrust.cs
- updatecommandorderer.cs
- LayoutDump.cs
- InternalPolicyElement.cs
- RectAnimationBase.cs
- SoapProtocolImporter.cs
- WizardStepBase.cs
- CompilerScopeManager.cs
- DesignerSerializationOptionsAttribute.cs
- EdmPropertyAttribute.cs
- BamlResourceSerializer.cs
- SamlAuthorityBinding.cs
- InputBuffer.cs
- IsolatedStorage.cs
- ConditionalAttribute.cs
- XmlEventCache.cs
- DataBindingHandlerAttribute.cs
- ImportException.cs
- RotateTransform.cs
- TextFindEngine.cs
- DateTimeOffset.cs
- PropertiesTab.cs
- SymmetricKeyWrap.cs
- ApplicationContext.cs
- WebSysDefaultValueAttribute.cs
- InfoCardRSACryptoProvider.cs
- MimeWriter.cs
- LinqDataSourceEditData.cs
- DataControlFieldTypeEditor.cs
- BulletedListEventArgs.cs
- relpropertyhelper.cs
- TraceSource.cs
- CompositeControl.cs
- Util.cs
- Win32SafeHandles.cs
- UniqueID.cs
- LocalBuilder.cs
- WebEventCodes.cs
- CodePrimitiveExpression.cs
- SqlTopReducer.cs
- RoutedEventValueSerializer.cs
- RootProfilePropertySettingsCollection.cs
- TypeSystem.cs
- HuffCodec.cs
- StatusBarAutomationPeer.cs
- FileDialog.cs
- XmlWriter.cs
- DesignerTextBoxAdapter.cs
- DocumentXPathNavigator.cs
- NativeMethods.cs
- PagesChangedEventArgs.cs
- Int64Converter.cs
- Baml2006KeyRecord.cs
- InternalPolicyElement.cs
- FilteredAttributeCollection.cs
- DataGridCell.cs
- DaylightTime.cs
- AmbientValueAttribute.cs
- CodeNamespaceCollection.cs
- clipboard.cs
- HashUtility.cs
- NonSerializedAttribute.cs
- TraceListener.cs
- DataGridState.cs
- GrammarBuilderWildcard.cs
- CursorEditor.cs
- ContractAdapter.cs
- XmlNodeChangedEventArgs.cs
- FormViewCommandEventArgs.cs
- ServiceMemoryGates.cs
- DialogResultConverter.cs
- SrgsElementList.cs
- MissingManifestResourceException.cs
- ListViewInsertedEventArgs.cs
- SerTrace.cs
- DependencyPropertyValueSerializer.cs
- ResourceReferenceExpression.cs
- SQLBinary.cs
- X509ChainPolicy.cs
- GridViewDeletedEventArgs.cs