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

◆ ImportEncryptedPkcs8PrivateKey() [4/4]

static unsafe Pkcs8Response System.Security.Cryptography.CngPkcs8.ImportEncryptedPkcs8PrivateKey ( ReadOnlySpan< char > password,
ReadOnlySpan< byte > source,
out int bytesRead )
inlinestaticpackage

Definition at line 176 of file CngPkcs8.cs.

177 {
178 try
179 {
180 AsnDecoder.ReadEncodedValue(source, AsnEncodingRules.BER, out var _, out var _, out var bytesConsumed);
181 source = source.Slice(0, bytesConsumed);
182 fixed (byte* pointer = &MemoryMarshal.GetReference(source))
183 {
184 using MemoryManager<byte> memoryManager = new System.Buffers.PointerMemoryManager<byte>(pointer, source.Length);
185 try
186 {
187 bytesRead = bytesConsumed;
188 return ImportPkcs8(source, password);
189 }
190 catch (CryptographicException)
191 {
192 }
193 int bytesRead2;
194 ArraySegment<byte> arraySegment = System.Security.Cryptography.KeyFormatHelper.DecryptPkcs8(password, memoryManager.Memory.Slice(0, bytesConsumed), out bytesRead2);
195 Span<byte> span = arraySegment;
196 try
197 {
198 if (bytesRead2 != bytesConsumed)
199 {
200 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding);
201 }
202 bytesRead = bytesConsumed;
203 return ImportPkcs8(span);
204 }
205 catch (CryptographicException inner)
206 {
208 if (asnWriter == null)
209 {
210 throw new CryptographicException(System.SR.Cryptography_Pkcs8_EncryptedReadFailed, inner);
211 }
212 try
213 {
214 bytesRead = bytesConsumed;
215 return ImportPkcs8(asnWriter);
216 }
217 catch (CryptographicException)
218 {
219 throw new CryptographicException(System.SR.Cryptography_Pkcs8_EncryptedReadFailed, inner);
220 }
221 }
222 finally
223 {
225 }
226 }
227 }
228 catch (AsnContentException inner2)
229 {
230 throw new CryptographicException(System.SR.Cryptography_Der_Invalid_Encoding, inner2);
231 }
232 }
static Asn1Tag ReadEncodedValue(ReadOnlySpan< byte > source, AsnEncodingRules ruleSet, out int contentOffset, out int contentLength, out int bytesConsumed)
Definition AsnDecoder.cs:57
static string Cryptography_Der_Invalid_Encoding
Definition SR.cs:50
static string Cryptography_Pkcs8_EncryptedReadFailed
Definition SR.cs:126
Definition SR.cs:7
static Pkcs8Response ImportPkcs8(ReadOnlySpan< byte > keyBlob)
Definition CngPkcs8.cs:28
static unsafe AsnWriter RewritePkcs8ECPrivateKeyWithZeroPublicKey(ReadOnlySpan< byte > source)
Definition CngPkcs8.cs:278
static void Return(byte[] array, int clearSize=-1)
Definition CryptoPool.cs:12
static ArraySegment< byte > DecryptPkcs8(ReadOnlySpan< char > inputPassword, ReadOnlyMemory< byte > source, out int bytesRead)

References System.SR.Cryptography_Der_Invalid_Encoding, System.SR.Cryptography_Pkcs8_EncryptedReadFailed, System.Security.Cryptography.KeyFormatHelper.DecryptPkcs8(), System.Security.Cryptography.CngPkcs8.ImportPkcs8(), System.pointer, System.Formats.Asn1.AsnDecoder.ReadEncodedValue(), System.Security.Cryptography.CryptoPool.Return(), System.Security.Cryptography.CngPkcs8.RewritePkcs8ECPrivateKeyWithZeroPublicKey(), and System.source.