Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- ObservableDictionary.cs
- ForeignKeyConstraint.cs
- SmtpCommands.cs
- AttributeTable.cs
- AuthStoreRoleProvider.cs
- ComNativeDescriptor.cs
- PeerCredentialElement.cs
- SoapExtensionStream.cs
- EnvelopedPkcs7.cs
- DataContractJsonSerializer.cs
- DataGridViewRowCancelEventArgs.cs
- SettingsContext.cs
- EncryptedData.cs
- Item.cs
- ReachBasicContext.cs
- XmlDataLoader.cs
- FileDialog_Vista.cs
- DbException.cs
- TriggerActionCollection.cs
- InvariantComparer.cs
- WindowsFormsLinkLabel.cs
- ContextInformation.cs
- ConfigurationSectionGroupCollection.cs
- FamilyTypefaceCollection.cs
- XmlCompatibilityReader.cs
- DataGridViewCellStyleChangedEventArgs.cs
- ViewManager.cs
- X509Certificate2Collection.cs
- SelectionChangedEventArgs.cs
- ElementHostAutomationPeer.cs
- SpnegoTokenProvider.cs
- ReferenceTypeElement.cs
- UpdatePanelTriggerCollection.cs
- NodeFunctions.cs
- ExpressionTable.cs
- DocumentApplicationJournalEntry.cs
- TextTrailingCharacterEllipsis.cs
- Int16.cs
- ListContractAdapter.cs
- ConfigXmlCDataSection.cs
- IntSecurity.cs
- SemanticResolver.cs
- UIntPtr.cs
- RequestStatusBarUpdateEventArgs.cs
- ToolStripContainer.cs
- HttpCacheVaryByContentEncodings.cs
- grammarelement.cs
- DataSourceXmlAttributeAttribute.cs
- BulletedListEventArgs.cs
- CodeAccessPermission.cs
- UIElementAutomationPeer.cs
- PkcsUtils.cs
- BreakRecordTable.cs
- XmlParser.cs
- DecimalConstantAttribute.cs
- CharStorage.cs
- InfoCardArgumentException.cs
- SimpleBitVector32.cs
- CustomAttributeBuilder.cs
- XNodeNavigator.cs
- NativeObjectSecurity.cs
- SizeAnimationClockResource.cs
- PenLineCapValidation.cs
- CommentEmitter.cs
- LinkArea.cs
- LeftCellWrapper.cs
- InvokeSchedule.cs
- MulticastOption.cs
- DataGridPageChangedEventArgs.cs
- ExpressionNode.cs
- WriterOutput.cs
- TextFormattingConverter.cs
- RegexStringValidatorAttribute.cs
- GradientStop.cs
- Command.cs
- GraphicsState.cs
- SchemaNames.cs
- StrongNameHelpers.cs
- DtdParser.cs
- XmlSchemaElement.cs
- ScrollItemPattern.cs
- Merger.cs
- UpdateException.cs
- CodeStatementCollection.cs
- OptionalColumn.cs
- UrlRoutingHandler.cs
- CollectionView.cs
- SmiGettersStream.cs
- LoadItemsEventArgs.cs
- SpellerError.cs
- TransformGroup.cs
- SafeEventLogWriteHandle.cs
- ISCIIEncoding.cs
- Stackframe.cs
- ComponentCodeDomSerializer.cs
- StateChangeEvent.cs
- AsyncCompletedEventArgs.cs
- DataGridViewDataConnection.cs
- XXXInfos.cs
- TerminatorSinks.cs