Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ InitiateEncryption() [2/2]

static void System.Security.Cryptography.PasswordBasedEncryption.InitiateEncryption ( PbeParameters pbeParameters,
out SymmetricAlgorithm cipher,
out string hmacOid,
out string encryptionAlgorithmOid,
out bool isPkcs12 )
inlinestaticpackage

Definition at line 148 of file PasswordBasedEncryption.cs.

149 {
150 isPkcs12 = false;
151 switch (pbeParameters.EncryptionAlgorithm)
152 {
153 case PbeEncryptionAlgorithm.Aes128Cbc:
154 cipher = Aes.Create();
155 cipher.KeySize = 128;
156 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.2";
157 break;
158 case PbeEncryptionAlgorithm.Aes192Cbc:
159 cipher = Aes.Create();
160 cipher.KeySize = 192;
161 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.22";
162 break;
163 case PbeEncryptionAlgorithm.Aes256Cbc:
164 cipher = Aes.Create();
165 cipher.KeySize = 256;
166 encryptionAlgorithmOid = "2.16.840.1.101.3.4.1.42";
167 break;
168 case PbeEncryptionAlgorithm.TripleDes3KeyPkcs12:
169 cipher = TripleDES.Create();
170 cipher.KeySize = 192;
171 encryptionAlgorithmOid = "1.2.840.113549.1.12.1.3";
172 isPkcs12 = true;
173 break;
174 default:
175 throw new CryptographicException(System.SR.Format(System.SR.Cryptography_UnknownAlgorithmIdentifier, pbeParameters.HashAlgorithm.Name));
176 }
177 HashAlgorithmName hashAlgorithm = pbeParameters.HashAlgorithm;
178 if (hashAlgorithm == HashAlgorithmName.SHA256)
179 {
180 hmacOid = "1.2.840.113549.2.9";
181 return;
182 }
183 if (hashAlgorithm == HashAlgorithmName.SHA384)
184 {
185 hmacOid = "1.2.840.113549.2.10";
186 return;
187 }
188 if (hashAlgorithm == HashAlgorithmName.SHA512)
189 {
190 hmacOid = "1.2.840.113549.2.11";
191 return;
192 }
193 if (hashAlgorithm == HashAlgorithmName.SHA1)
194 {
195 hmacOid = "1.2.840.113549.2.7";
196 return;
197 }
198 cipher.Dispose();
199 throw new CryptographicException(System.SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name);
200 }
static string Cryptography_UnknownAlgorithmIdentifier
Definition SR.cs:150
static string Cryptography_UnknownHashAlgorithm
Definition SR.cs:152
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7

References System.Security.Cryptography.Aes.Create(), System.Security.Cryptography.TripleDES.Create(), System.SR.Cryptography_UnknownAlgorithmIdentifier, System.SR.Cryptography_UnknownHashAlgorithm, System.Security.Cryptography.PbeParameters.EncryptionAlgorithm, System.SR.Format(), System.Security.Cryptography.PbeParameters.HashAlgorithm, System.Security.Cryptography.HashAlgorithmName.Name, System.Security.Cryptography.HashAlgorithmName.SHA1, System.Security.Cryptography.HashAlgorithmName.SHA256, System.Security.Cryptography.HashAlgorithmName.SHA384, and System.Security.Cryptography.HashAlgorithmName.SHA512.