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
- XhtmlTextWriter.cs
- IApplicationTrustManager.cs
- DesignerDataConnection.cs
- SystemInfo.cs
- NativeCppClassAttribute.cs
- XXXInfos.cs
- NativeMethods.cs
- Lease.cs
- RootNamespaceAttribute.cs
- ChannelOptions.cs
- BindingContext.cs
- AutomationProperty.cs
- FileChangesMonitor.cs
- OracleString.cs
- RecordConverter.cs
- Literal.cs
- TdsParserSafeHandles.cs
- EntityDesignerUtils.cs
- SqlClientPermission.cs
- SiteMapPath.cs
- ellipse.cs
- StreamUpdate.cs
- SecurityHeaderLayout.cs
- NativeMethods.cs
- Registration.cs
- InternalTransaction.cs
- DataRelationCollection.cs
- BrushValueSerializer.cs
- CollaborationHelperFunctions.cs
- CategoriesDocumentFormatter.cs
- SequenceDesigner.cs
- BaseWebProxyFinder.cs
- SurrogateSelector.cs
- HeaderCollection.cs
- SQLCharsStorage.cs
- DrawingVisual.cs
- Rectangle.cs
- XmlFileEditor.cs
- DateRangeEvent.cs
- IndentTextWriter.cs
- EmptyQuery.cs
- DocumentOrderComparer.cs
- Converter.cs
- CompositeControlDesigner.cs
- ContentWrapperAttribute.cs
- Action.cs
- ButtonBaseAutomationPeer.cs
- DataPagerFieldItem.cs
- AnnotationDocumentPaginator.cs
- UnsafeNativeMethodsTablet.cs
- DataRowCollection.cs
- InternalControlCollection.cs
- HtmlElementCollection.cs
- MDIControlStrip.cs
- WebSysDescriptionAttribute.cs
- ThreadWorkerController.cs
- StateMachineSubscription.cs
- EnumerationRangeValidationUtil.cs
- ProcessModule.cs
- SafeArrayTypeMismatchException.cs
- BitmapCache.cs
- SwitchAttribute.cs
- PropertyGridView.cs
- Package.cs
- DatagridviewDisplayedBandsData.cs
- ExpressionBuilderContext.cs
- DocumentReferenceCollection.cs
- Bidi.cs
- Set.cs
- PointValueSerializer.cs
- EntityTypeBase.cs
- VectorKeyFrameCollection.cs
- ActivityMetadata.cs
- ElementFactory.cs
- TextOutput.cs
- ChangeProcessor.cs
- TreeNodeCollection.cs
- ShadowGlyph.cs
- ToolStripMenuItemCodeDomSerializer.cs
- ReferenceService.cs
- DefaultBindingPropertyAttribute.cs
- IRCollection.cs
- WmlImageAdapter.cs
- wmiprovider.cs
- SafeCloseHandleCritical.cs
- OracleInfoMessageEventArgs.cs
- ApplicationFileCodeDomTreeGenerator.cs
- OracleInternalConnection.cs
- DbProviderServices.cs
- BoolExpression.cs
- PropertyNames.cs
- BindMarkupExtensionSerializer.cs
- CreateUserWizardStep.cs
- BamlVersionHeader.cs
- arabicshape.cs
- SqlSelectStatement.cs
- CodeGenerator.cs
- QuaternionRotation3D.cs
- TraceSection.cs
- BufferedOutputStream.cs