-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInadequateRSAPadding.cs
More file actions
41 lines (36 loc) · 1.07 KB
/
InadequateRSAPadding.cs
File metadata and controls
41 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Security.Cryptography;
namespace InadequateRSAPadding
{
class Main
{
static public byte[] EncryptWithRSAAndNoPadding(byte[] plaintext, RSAParameters key)
{
try
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(key);
return rsa.Encrypt(plaintext, false); // BAD
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
static public byte[] EncryptWithRSAAndPadding(byte[] plaintext, RSAParameters key)
{
try
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(key);
return rsa.Encrypt(plaintext, true); // GOOD
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
}
}
}