Skip to content

Commit 292b7b7

Browse files
committed
Merge branch 'master' into publish-23342
2 parents 01e92e5 + 24edf30 commit 292b7b7

File tree

157 files changed

+563
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+563
-542
lines changed

samples/snippets/cpp/VS_Snippets_CLR/rfc28981/CPP/rfc28981.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main()
4646
//</SNIPPET4>
4747

4848
// Encrypt the data.
49-
TripleDES^ encAlg = TripleDES::Create();
49+
Aes^ encAlg = Aes::Create();
5050
encAlg->Key = k1->GetBytes( 16 );
5151
MemoryStream^ encryptionStream = gcnew MemoryStream;
5252
CryptoStream^ encrypt = gcnew CryptoStream( encryptionStream,encAlg->CreateEncryptor(),CryptoStreamMode::Write );
@@ -60,7 +60,7 @@ int main()
6060
k1->Reset();
6161

6262
// Try to decrypt, thus showing it can be round-tripped.
63-
TripleDES^ decAlg = TripleDES::Create();
63+
Aes^ decAlg = Aes::Create();
6464
decAlg->Key = k2->GetBytes( 16 );
6565
decAlg->IV = encAlg->IV;
6666
MemoryStream^ decryptionStreamBacking = gcnew MemoryStream;

samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CPP/sample.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ int main()
3131
//Import key parameters into RSA.
3232
RSA->ImportParameters( RSAKeyInfo );
3333

34-
//Create a new instance of the RijndaelManaged class.
35-
RijndaelManaged^ RM = gcnew RijndaelManaged;
34+
//Create a new instance of the Aes class.
35+
Aes^ aes = gcnew Aes;
3636

3737
//Encrypt the symmetric key and IV.
38-
EncryptedSymmetricKey = RSA->Encrypt( RM->Key, false );
39-
EncryptedSymmetricIV = RSA->Encrypt( RM->IV, false );
40-
Console::WriteLine( "RijndaelManaged Key and IV have been encrypted with RSACryptoServiceProvider." );
38+
EncryptedSymmetricKey = RSA->Encrypt( aes->Key, false );
39+
EncryptedSymmetricIV = RSA->Encrypt( aes->IV, false );
40+
Console::WriteLine( "Aes Key and IV have been encrypted with RSACryptoServiceProvider." );
4141
}
4242
catch ( CryptographicException^ e )
4343
{

samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.XML.SignedXml.ComputeSig-Check-KeyedHash-Detached/CPP/xmldsigdetachedkeyedhashalg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int main()
8383
String^ XmlFileName = "xmlsig.xml";
8484

8585
// Generate a signing key.
86-
HMACSHA1^ Key = gcnew HMACSHA1;
86+
HMACSHA256^ Key = gcnew HMACSHA256;
8787
Console::WriteLine( "Signing: {0}", resourceToSign );
8888

8989
// Sign the detached resourceand save the signature in an XML file.

samples/snippets/cpp/VS_Snippets_CLR_System/system.Security.Cryptography.XML.SignedXml.ComputeSig-Check-KeyedHash-Envelope/CPP/xmldsigenvkeyedhashalg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int main()
123123
{
124124

125125
// Generate a signing key.
126-
HMACSHA1^ Key = gcnew HMACSHA1;
126+
HMACSHA256^ Key = gcnew HMACSHA256;
127127

128128
// Create an XML file to sign.
129129
CreateSomeXml( "Example.xml" );

samples/snippets/csharp/VS_Snippets_CLR/rfc28981/CS/rfc28981.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void Main(string[] passwordargs)
4848
Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);
4949
//</SNIPPET4>
5050
// Encrypt the data.
51-
TripleDES encAlg = TripleDES.Create();
51+
Aes encAlg = Aes.Create();
5252
encAlg.Key = k1.GetBytes(16);
5353
MemoryStream encryptionStream = new MemoryStream();
5454
CryptoStream encrypt = new CryptoStream(encryptionStream,
@@ -64,7 +64,7 @@ public static void Main(string[] passwordargs)
6464
k1.Reset();
6565

6666
// Try to decrypt, thus showing it can be round-tripped.
67-
TripleDES decAlg = TripleDES.Create();
67+
Aes decAlg = Aes.Create();
6868
decAlg.Key = k2.GetBytes(16);
6969
decAlg.IV = encAlg.IV;
7070
MemoryStream decryptionStreamBacking = new MemoryStream();

samples/snippets/csharp/VS_Snippets_CLR/x509certificate2/cs/program.cs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,16 @@ private static X509Certificate2 GetCertificateFromStore(string certName)
8282
// Encrypt a file using a public key.
8383
private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPublicKey)
8484
{
85-
using (AesManaged aesManaged = new AesManaged())
85+
using (Aes aes = new Aes())
8686
{
87-
// Create instance of AesManaged for
87+
// Create instance of Aes for
8888
// symetric encryption of the data.
89-
aesManaged.KeySize = 256;
90-
aesManaged.BlockSize = 128;
91-
aesManaged.Mode = CipherMode.CBC;
92-
using (ICryptoTransform transform = aesManaged.CreateEncryptor())
89+
aes.KeySize = 256;
90+
aes.Mode = CipherMode.CBC;
91+
using (ICryptoTransform transform = aes.CreateEncryptor())
9392
{
9493
RSAPKCS1KeyExchangeFormatter keyFormatter = new RSAPKCS1KeyExchangeFormatter(rsaPublicKey);
95-
byte[] keyEncrypted = keyFormatter.CreateKeyExchange(aesManaged.Key, aesManaged.GetType());
94+
byte[] keyEncrypted = keyFormatter.CreateKeyExchange(aes.Key, aes.GetType());
9695

9796
// Create byte arrays to contain
9897
// the length values of the key and IV.
@@ -101,7 +100,7 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli
101100

102101
int lKey = keyEncrypted.Length;
103102
LenK = BitConverter.GetBytes(lKey);
104-
int lIV = aesManaged.IV.Length;
103+
int lIV = aes.IV.Length;
105104
LenIV = BitConverter.GetBytes(lIV);
106105

107106
// Write the following to the FileStream
@@ -123,7 +122,7 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli
123122
outFs.Write(LenK, 0, 4);
124123
outFs.Write(LenIV, 0, 4);
125124
outFs.Write(keyEncrypted, 0, lKey);
126-
outFs.Write(aesManaged.IV, 0, lIV);
125+
outFs.Write(aes.IV, 0, lIV);
127126

128127
// Now write the cipher text using
129128
// a CryptoStream for encrypting.
@@ -137,7 +136,7 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli
137136
int offset = 0;
138137

139138
// blockSizeBytes can be any arbitrary size.
140-
int blockSizeBytes = aesManaged.BlockSize / 8;
139+
int blockSizeBytes = aes.BlockSize / 8;
141140
byte[] data = new byte[blockSizeBytes];
142141
int bytesRead = 0;
143142

@@ -169,13 +168,12 @@ private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPubli
169168
private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPrivateKey)
170169
{
171170

172-
// Create instance of AesManaged for
171+
// Create instance of Aes for
173172
// symetric decryption of the data.
174-
using (AesManaged aesManaged = new AesManaged())
173+
using (Aes aes = new Aes())
175174
{
176-
aesManaged.KeySize = 256;
177-
aesManaged.BlockSize = 128;
178-
aesManaged.Mode = CipherMode.CBC;
175+
aes.KeySize = 256;
176+
aes.Mode = CipherMode.CBC;
179177

180178
// Create byte arrays to get the length of
181179
// the encrypted key and IV.
@@ -202,14 +200,14 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva
202200
int lenK = BitConverter.ToInt32(LenK, 0);
203201
int lenIV = BitConverter.ToInt32(LenIV, 0);
204202

205-
// Determine the start postition of
206-
// the ciphter text (startC)
203+
// Determine the start position of
204+
// the cipher text (startC)
207205
// and its length(lenC).
208206
int startC = lenK + lenIV + 8;
209207
int lenC = (int)inFs.Length - startC;
210208

211209
// Create the byte arrays for
212-
// the encrypted AesManaged key,
210+
// the encrypted Aes key,
213211
// the IV, and the cipher text.
214212
byte[] KeyEncrypted = new byte[lenK];
215213
byte[] IV = new byte[lenIV];
@@ -224,11 +222,11 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva
224222
Directory.CreateDirectory(decrFolder);
225223
//<Snippet10>
226224
// Use RSACryptoServiceProvider
227-
// to decrypt the AesManaged key.
225+
// to decrypt the Aes key.
228226
byte[] KeyDecrypted = rsaPrivateKey.Decrypt(KeyEncrypted, false);
229227

230228
// Decrypt the key.
231-
using (ICryptoTransform transform = aesManaged.CreateDecryptor(KeyDecrypted, IV))
229+
using (ICryptoTransform transform = aes.CreateDecryptor(KeyDecrypted, IV))
232230
{
233231
//</Snippet10>
234232

@@ -242,7 +240,7 @@ private static void DecryptFile(string inFile, RSACryptoServiceProvider rsaPriva
242240
int count = 0;
243241
int offset = 0;
244242

245-
int blockSizeBytes = aesManaged.BlockSize / 8;
243+
int blockSizeBytes = aes.BlockSize / 8;
246244
byte[] data = new byte[blockSizeBytes];
247245

248246
// By decrypting a chunk a time,

samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.RSACryptoServiceProvider.Encrypt/CS/sample.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ static void Main()
3737
//Import key parameters into RSA.
3838
RSA.ImportParameters(RSAKeyInfo);
3939

40-
//Create a new instance of the RijndaelManaged class.
41-
RijndaelManaged RM = new RijndaelManaged();
40+
//Create a new instance of the Aes class.
41+
Aes aes = new Aes();
4242

4343
//Encrypt the symmetric key and IV.
44-
EncryptedSymmetricKey = RSA.Encrypt(RM.Key, false);
45-
EncryptedSymmetricIV = RSA.Encrypt(RM.IV, false);
44+
EncryptedSymmetricKey = RSA.Encrypt(aes.Key, false);
45+
EncryptedSymmetricIV = RSA.Encrypt(aes.IV, false);
4646

47-
Console.WriteLine("RijndaelManaged Key and IV have been encrypted with RSACryptoServiceProvider.");
47+
Console.WriteLine("Aes Key and IV have been encrypted with RSACryptoServiceProvider.");
4848
}
4949
//Catch and display a CryptographicException
5050
//to the console.

samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.XML.SignedXml.ComputeSig-Check-KeyedHash-Detached/CS/xmldsigdetachedkeyedhashalg.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void Main(string[] args)
2626
string XmlFileName = "xmlsig.xml";
2727

2828
// Generate a signing key.
29-
HMACSHA1 Key = new HMACSHA1();
29+
HMACSHA256 Key = new HMACSHA256();
3030

3131
Console.WriteLine("Signing: {0}", resourceToSign);
3232

samples/snippets/csharp/VS_Snippets_CLR_System/system.Security.Cryptography.XML.SignedXml.ComputeSig-Check-KeyedHash-Envelope/CS/xmldsigenvkeyedhashalg.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void Main(String[] args)
2020
{
2121

2222
// Generate a signing key.
23-
HMACSHA1 Key = new HMACSHA1();
23+
HMACSHA256 Key = new HMACSHA256();
2424

2525
// Create an XML file to sign.
2626
CreateSomeXml("Example.xml");

samples/snippets/csharp/VS_Snippets_WebNet/System.Web.Security.IMembershipProvider/CS/imembershipprovider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,7 @@ private string EncodePassword(string password)
14451445
Convert.ToBase64String(EncryptPassword(Encoding.Unicode.GetBytes(password)));
14461446
break;
14471447
case MembershipPasswordFormat.Hashed:
1448-
HMACSHA1 hash = new HMACSHA1();
1448+
HMACSHA256 hash = new HMACSHA256();
14491449
hash.Key = HexToByte(machineKey.ValidationKey);
14501450
encodedPassword =
14511451
Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));

0 commit comments

Comments
 (0)