42 {
43 SymmetricAlgorithm symmetricAlgorithm = null;
44 bool flag = false;
45 HashAlgorithmName hashAlgorithm;
46 switch (algorithmIdentifier.Algorithm)
47 {
48 case "1.2.840.113549.1.5.3":
49 hashAlgorithm = HashAlgorithmName.MD5;
50 symmetricAlgorithm = DES.Create();
51 break;
52 case "1.2.840.113549.1.5.6":
53 hashAlgorithm = HashAlgorithmName.MD5;
55 break;
56 case "1.2.840.113549.1.5.10":
57 hashAlgorithm = HashAlgorithmName.SHA1;
58 symmetricAlgorithm = DES.Create();
59 break;
60 case "1.2.840.113549.1.5.11":
61 hashAlgorithm = HashAlgorithmName.SHA1;
63 break;
64 case "1.2.840.113549.1.12.1.3":
65 hashAlgorithm = HashAlgorithmName.SHA1;
66 symmetricAlgorithm = TripleDES.Create();
67 flag = true;
68 break;
69 case "1.2.840.113549.1.12.1.4":
70 hashAlgorithm = HashAlgorithmName.SHA1;
71 symmetricAlgorithm = TripleDES.Create();
72 symmetricAlgorithm.KeySize = 128;
73 flag = true;
74 break;
75 case "1.2.840.113549.1.12.1.5":
76 hashAlgorithm = HashAlgorithmName.SHA1;
78 symmetricAlgorithm.KeySize = 128;
79 flag = true;
80 break;
81 case "1.2.840.113549.1.12.1.6":
82 hashAlgorithm = HashAlgorithmName.SHA1;
84 symmetricAlgorithm.KeySize = 40;
85 flag = true;
86 break;
87 case "1.2.840.113549.1.5.13":
89 default:
91 }
92 using (symmetricAlgorithm)
93 {
94 if (flag)
95 {
97 {
99 }
101 }
102 using IncrementalHash hasher = IncrementalHash.CreateHash(hashAlgorithm);
103 Span<byte> span = stackalloc byte[128];
104 ReadOnlySpan<byte> password2 = default(Span<byte>);
108 {
109 password2 = passwordBytes;
110 }
111 else
112 {
116 {
119 }
120 else
121 {
123 }
124 }
126 {
127 if (encoding != null)
128 {
129 span = span[..encoding.
GetBytes(password, span)];
130 password2 = span;
131 }
132 try
133 {
134 return Pbes1Decrypt(algorithmIdentifier.Parameters, password2, hasher, symmetricAlgorithm, encryptedData,
destination);
135 }
136 finally
137 {
138 CryptographicOperations.ZeroMemory(span);
140 {
142 }
143 }
144 }
145 }
146 }
static string Cryptography_UnknownAlgorithmIdentifier
static string Format(string resourceFormat, object p1)
static void Return(byte[] array, int clearSize=-1)
static byte[] Rent(int minimumLength)
static int Pbes1Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< byte > password, IncrementalHash hasher, SymmetricAlgorithm cipher, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static unsafe int Pbes2Decrypt(ReadOnlyMemory< byte >? algorithmParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static int Pkcs12PbeDecrypt(AlgorithmIdentifierAsn algorithmIdentifier, ReadOnlySpan< char > password, HashAlgorithmName hashAlgorithm, SymmetricAlgorithm cipher, ReadOnlySpan< byte > encryptedData, Span< byte > destination)
static CryptographicException AlgorithmKdfRequiresChars(string algId)
virtual byte[] GetBytes(char[] chars)
virtual int GetByteCount(char[] chars)