1+ // Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+ // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+ using System . IO ;
5+ using System . Reflection ;
6+ using System . Security . Cryptography . X509Certificates ;
7+
8+ namespace Identity . API . Certificate
9+ {
10+ static class Certificate
11+ {
12+ public static X509Certificate2 Get ( )
13+ {
14+ var assembly = typeof ( Certificate ) . GetTypeInfo ( ) . Assembly ;
15+ var names = assembly . GetManifestResourceNames ( ) ;
16+
17+ /***********************************************************************************************
18+ * Please note that here we are using a local certificate only for testing purposes. In a
19+ * real environment the certificate should be created and stored in a secure way, which is out
20+ * of the scope of this project.
21+ **********************************************************************************************/
22+ using ( var stream = assembly . GetManifestResourceStream ( "Identity.API.Certificate.idsrv3test.pfx" ) )
23+ {
24+ return new X509Certificate2 ( ReadStream ( stream ) , "idsrv3test" ) ;
25+ }
26+ }
27+
28+ private static byte [ ] ReadStream ( Stream input )
29+ {
30+ byte [ ] buffer = new byte [ 16 * 1024 ] ;
31+ using ( MemoryStream ms = new MemoryStream ( ) )
32+ {
33+ int read ;
34+ while ( ( read = input . Read ( buffer , 0 , buffer . Length ) ) > 0 )
35+ {
36+ ms . Write ( buffer , 0 , read ) ;
37+ }
38+ return ms . ToArray ( ) ;
39+ }
40+ }
41+ }
42+ }
0 commit comments