Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Security / Cryptography / RijndaelManaged.cs / 1305376 / RijndaelManaged.cs
using System.Diagnostics.Contracts;
// ==++==
//
// 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 FEATURE_CRYPTO
if (CryptoConfig.AllowOnlyFipsAlgorithms)
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
Contract.EndContractBlock();
#endif // FEATURE_CRYPTO
}
// #CoreCLRRijndaelModes
//
// On CoreCLR we limit the supported cipher modes and padding modes for the AES algorithm to a
// single hard coded value. This allows us to remove a lot of code by removing support for the
// uncommon cases and forcing everyone to use the same common padding and ciper modes:
//
// - CipherMode: CipherMode.CBC
// - PaddingMode: PaddingMode.PKCS7
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 = Utils.GenerateRandom(KeySizeValue / 8);
}
public override void GenerateIV () {
IVValue = Utils.GenerateRandom(BlockSizeValue / 8);
}
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 = Utils.GenerateRandom(KeySizeValue / 8);
}
// If not ECB mode, make sure we have an IV. In CoreCLR we do not support ECB, so we must have
// an IV in all cases.
#if !FEATURE_CRYPTO
if (mode != CipherMode.ECB) {
#endif // !FEATURE_CRYPTO
if (rgbIV == null) {
rgbIV = Utils.GenerateRandom(BlockSizeValue / 8);
}
#if !FEATURE_CRYPTO
}
#endif // !FEATURE_CRYPTO
// 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.
using System.Diagnostics.Contracts;
// ==++==
//
// 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 FEATURE_CRYPTO
if (CryptoConfig.AllowOnlyFipsAlgorithms)
throw new InvalidOperationException(Environment.GetResourceString("Cryptography_NonCompliantFIPSAlgorithm"));
Contract.EndContractBlock();
#endif // FEATURE_CRYPTO
}
// #CoreCLRRijndaelModes
//
// On CoreCLR we limit the supported cipher modes and padding modes for the AES algorithm to a
// single hard coded value. This allows us to remove a lot of code by removing support for the
// uncommon cases and forcing everyone to use the same common padding and ciper modes:
//
// - CipherMode: CipherMode.CBC
// - PaddingMode: PaddingMode.PKCS7
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 = Utils.GenerateRandom(KeySizeValue / 8);
}
public override void GenerateIV () {
IVValue = Utils.GenerateRandom(BlockSizeValue / 8);
}
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 = Utils.GenerateRandom(KeySizeValue / 8);
}
// If not ECB mode, make sure we have an IV. In CoreCLR we do not support ECB, so we must have
// an IV in all cases.
#if !FEATURE_CRYPTO
if (mode != CipherMode.ECB) {
#endif // !FEATURE_CRYPTO
if (rgbIV == null) {
rgbIV = Utils.GenerateRandom(BlockSizeValue / 8);
}
#if !FEATURE_CRYPTO
}
#endif // !FEATURE_CRYPTO
// 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FixedSOMTableCell.cs
- StyleBamlRecordReader.cs
- KeyValueInternalCollection.cs
- EditorBrowsableAttribute.cs
- COAUTHINFO.cs
- ObjectDataSourceEventArgs.cs
- RadioButton.cs
- XPathNodeInfoAtom.cs
- SqlDataSourceQueryEditorForm.cs
- EditingCoordinator.cs
- DeclarativeCatalogPartDesigner.cs
- TransformGroup.cs
- GlobalDataBindingHandler.cs
- RegexMatchCollection.cs
- FilterException.cs
- ToolStripContainer.cs
- HttpHeaderCollection.cs
- DataGridViewMethods.cs
- ProgressBarRenderer.cs
- CompiledRegexRunner.cs
- CFGGrammar.cs
- EnumerableWrapperWeakToStrong.cs
- PrivilegedConfigurationManager.cs
- SimpleTableProvider.cs
- DefaultProfileManager.cs
- SortQuery.cs
- WeakReference.cs
- Marshal.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- SoundPlayerAction.cs
- DesignTimeTemplateParser.cs
- Lock.cs
- InputLanguageEventArgs.cs
- KeyValueConfigurationElement.cs
- AbstractExpressions.cs
- PenThread.cs
- ServiceMemoryGates.cs
- PKCS1MaskGenerationMethod.cs
- COM2AboutBoxPropertyDescriptor.cs
- LateBoundBitmapDecoder.cs
- ConstantProjectedSlot.cs
- DispatcherTimer.cs
- SiteMapNode.cs
- OutKeywords.cs
- CustomAttribute.cs
- QueryOperator.cs
- DesignerDataRelationship.cs
- TypeUnloadedException.cs
- ClassicBorderDecorator.cs
- Asn1Utilities.cs
- CalendarDay.cs
- DocumentReferenceCollection.cs
- BitmapImage.cs
- FormViewInsertEventArgs.cs
- TraceSwitch.cs
- ImageDrawing.cs
- ConfigurationPropertyCollection.cs
- KeyValuePairs.cs
- BuildProviderCollection.cs
- SettingsPropertyCollection.cs
- ACL.cs
- MessageBox.cs
- CqlBlock.cs
- TileModeValidation.cs
- SinglePageViewer.cs
- XslCompiledTransform.cs
- InfoCardPolicy.cs
- GlyphElement.cs
- ProgressBarAutomationPeer.cs
- BrushMappingModeValidation.cs
- MaskedTextProvider.cs
- UriParserTemplates.cs
- EncryptedPackage.cs
- ToggleProviderWrapper.cs
- BaseHashHelper.cs
- XmlReflectionImporter.cs
- COM2EnumConverter.cs
- AppDomainAttributes.cs
- TypeHelper.cs
- XPathNodeHelper.cs
- GenerateScriptTypeAttribute.cs
- Tile.cs
- ClientTargetCollection.cs
- VariableExpressionConverter.cs
- CheckBoxField.cs
- GlobalizationSection.cs
- CompiledQueryCacheEntry.cs
- Int64Storage.cs
- Variant.cs
- DefaultParameterValueAttribute.cs
- FrameDimension.cs
- TextServicesManager.cs
- SQLCharsStorage.cs
- TextContainerChangeEventArgs.cs
- DataGridViewCellCancelEventArgs.cs
- AspCompat.cs
- OperationCanceledException.cs
- PointKeyFrameCollection.cs
- DateTimeHelper.cs
- DynamicQueryableWrapper.cs