| 
									
										
										
										
											2016-07-30 19:09:37 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var RSA = require('../').RSA; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:47:52 -04:00
										 |  |  | RSA.generateKeypair(null, null, null, function (err, keys) { | 
					
						
							| 
									
										
										
										
											2016-07-30 19:09:37 -04:00
										 |  |  |   if (!keys.privateKeyJwk) { | 
					
						
							|  |  |  |     throw new Error("Expected privateKeyJwk, but it is missing"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var options = { | 
					
						
							|  |  |  |     public: true        // export public keys
 | 
					
						
							|  |  |  |   , pem: true           // export pems
 | 
					
						
							|  |  |  |   , jwk: false          // export jwks
 | 
					
						
							|  |  |  |   , internal: true      // preserve internal intermediate formats (_ursa, _forge)
 | 
					
						
							| 
									
										
										
										
											2016-08-01 04:03:50 -04:00
										 |  |  |   //, thumbprint: true    // JWK sha256 thumbprint
 | 
					
						
							| 
									
										
										
										
											2016-07-30 19:09:37 -04:00
										 |  |  |   }; | 
					
						
							| 
									
										
										
										
											2016-07-30 23:47:52 -04:00
										 |  |  |   RSA.generateKeypair(512, 65537, options, function (err, keys) { | 
					
						
							|  |  |  |     if ( | 
					
						
							| 
									
										
										
										
											2016-08-01 04:03:50 -04:00
										 |  |  |         (keys.publicKeyJwk && !keys.thumbprint) | 
					
						
							|  |  |  |     || !keys.privateKeyPem | 
					
						
							|  |  |  |     || !keys.publicKeyPem | 
					
						
							|  |  |  |     //|| !keys.thumbprint
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:47:52 -04:00
										 |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2016-08-01 04:03:50 -04:00
										 |  |  |       console.error(Object.keys(keys)); | 
					
						
							|  |  |  |       throw new Error("Missing expected keys"); | 
					
						
							| 
									
										
										
										
											2016-07-30 23:47:52 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-08-01 04:03:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     console.log('All is well!'); | 
					
						
							| 
									
										
										
										
											2016-07-30 19:09:37 -04:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }); |