@@ -57,7 +57,7 @@ describe("Crypto", () => {
5757 it ( "with valid config with private keystore" , ( ) => {
5858 const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
5959 delete config . privateKey ;
60- config . keyStore = "./test/res/test_key.p12" ;
60+ config . keyStore = "./test/res/keys/pkcs12/ test_key.p12" ;
6161 config . keyStoreAlias = "mykeyalias" ;
6262 config . keyStorePassword = "Password1" ;
6363 assert . doesNotThrow ( ( ) => {
@@ -66,6 +66,36 @@ describe("Crypto", () => {
6666 ) ;
6767 } ) ;
6868
69+ it ( "with valid config with private pkcs1 pem keystore" , ( ) => {
70+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
71+ delete config . privateKey ;
72+ config . keyStore = "./test/res/keys/pkcs1/test_key.pem" ;
73+ assert . doesNotThrow ( ( ) => {
74+ new Crypto ( config ) ;
75+ }
76+ ) ;
77+ } ) ;
78+
79+ it ( "with valid config with private pkcs8 pem keystore" , ( ) => {
80+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
81+ delete config . privateKey ;
82+ config . keyStore = "./test/res/keys/pkcs8/test_key.pem" ;
83+ assert . doesNotThrow ( ( ) => {
84+ new Crypto ( config ) ;
85+ }
86+ ) ;
87+ } ) ;
88+
89+ it ( "with valid config with private pkcs8 der keystore" , ( ) => {
90+ const config = JSON . parse ( JSON . stringify ( testConfig ) ) ;
91+ delete config . privateKey ;
92+ config . keyStore = "./test/res/keys/pkcs8/test_key.der" ;
93+ assert . doesNotThrow ( ( ) => {
94+ new Crypto ( config ) ;
95+ }
96+ ) ;
97+ } ) ;
98+
6999 it ( "with valid config header" , ( ) => {
70100 assert . doesNotThrow ( ( ) =>
71101 new Crypto ( testConfigHeader )
@@ -233,8 +263,8 @@ describe("Crypto", () => {
233263 } ) ;
234264 } ) ;
235265
236- describe ( "#getPrivateKey " , ( ) => {
237- const getPrivateKey = Crypto . __get__ ( "getPrivateKey " ) ;
266+ describe ( "#getPrivateKey12 " , ( ) => {
267+ const getPrivateKey = Crypto . __get__ ( "getPrivateKey12 " ) ;
238268
239269 it ( "not valid key" , ( ) => {
240270 assert . throws ( ( ) => {
@@ -244,30 +274,65 @@ describe("Crypto", () => {
244274
245275 it ( "empty alias" , ( ) => {
246276 assert . throws ( ( ) => {
247- getPrivateKey ( "./test/res/test_key_container.p12" ) ;
277+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" ) ;
248278 } , / K e y a l i a s i s n o t s e t / ) ;
249279 } ) ;
250280
251281 it ( "empty password" , ( ) => {
252282 assert . throws ( ( ) => {
253- getPrivateKey ( "./test/res/test_key_container.p12" , "keyalias" ) ;
283+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "keyalias" ) ;
254284 } , / K e y s t o r e p a s s w o r d i s n o t s e t / ) ;
255285 } ) ;
256286
257287 it ( "valid p12" , ( ) => {
258- const pk = getPrivateKey ( "./test/res/test_key_container.p12" , "mykeyalias" , "Password1" ) ;
288+ const pk = getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "mykeyalias" , "Password1" ) ;
259289 assert . ok ( pk ) ;
260290 } ) ;
261291
262292 it ( "valid p12, alias not found" , ( ) => {
263293 assert . throws ( ( ) => {
264- getPrivateKey ( "./test/res/test_key_container.p12" , "mykeyalias1" , "Password1" ) ;
294+ getPrivateKey ( "./test/res/keys/pkcs12/ test_key_container.p12" , "mykeyalias1" , "Password1" ) ;
265295 } , / N o k e y f o u n d f o r a l i a s \[ m y k e y a l i a s 1 \] / ) ;
266296 } ) ;
267297 } ) ;
268298
299+ describe ( "#getPrivateKeyPem" , ( ) => {
300+ const getPrivateKeyPem = Crypto . __get__ ( "getPrivateKeyPem" ) ;
301+
302+ it ( "valid pkcs8 pem" , ( ) => {
303+ const pk = getPrivateKeyPem ( "./test/res/keys/pkcs8/test_key.pem" ) ;
304+ assert . ok ( pk ) ;
305+ } ) ;
306+
307+ it ( "valid pkcs1 pem" , ( ) => {
308+ const pk = getPrivateKeyPem ( "./test/res/keys/pkcs1/test_key.pem" ) ;
309+ assert . ok ( pk ) ;
310+ } ) ;
311+
312+ it ( "not valid key" , ( ) => {
313+ assert . throws ( ( ) => {
314+ getPrivateKeyPem ( "./test/res/empty.key" ) ;
315+ } , / p e m k e y s t o r e c o n t e n t i s e m p t y / ) ;
316+ } ) ;
317+ } ) ;
318+
319+ describe ( "#getPrivateKeyDer" , ( ) => {
320+ const getPrivateKeyDer = Crypto . __get__ ( "getPrivateKeyDer" ) ;
321+
322+ it ( "valid pkcs8 der" , ( ) => {
323+ const pk = getPrivateKeyDer ( "./test/res/keys/pkcs8/test_key.der" ) ;
324+ assert . ok ( pk ) ;
325+ } ) ;
326+
327+ it ( "not valid key" , ( ) => {
328+ assert . throws ( ( ) => {
329+ getPrivateKeyDer ( "./test/res/empty.key" ) ;
330+ } , / d e r k e y s t o r e c o n t e n t i s e m p t y / ) ;
331+ } ) ;
332+
333+ } )
269334
270- describe ( "#newEncryptionParams" , ( ) => {
335+ describe ( "#newEncryptionParams" , ( ) => {
271336 let crypto ;
272337 before ( ( ) => {
273338 crypto = new Crypto ( testConfig ) ;
0 commit comments