public void GetWebKeyFromCertificate()
        {
            string password = "******";
            string tempPath = Path.GetTempFileName() + ".pfx";

            File.WriteAllBytes(tempPath, Resource.pfxCert);

            IWebKeyConverter converters = WebKeyConverterFactory.CreateConverterChain();
            var webKey = converters.ConvertKeyFromFile(new FileInfo(tempPath), password.ConvertToSecureString());

            Assert.True(webKey.HasPrivateKey());
            Assert.True(webKey.IsValid());
            Assert.Equal(webKey.Kty, JsonWebKeyType.Rsa);
        }
        public void GetWebKeyFromCertificate()
        {
            string password = "******";
            // This allows the test to run in Visual Studio and in the console runner. The file will exist in one of the two locations depending on the environment.
            var consolePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? String.Empty, "Resources", "pshtest.pfx");
            var vsPath      = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "pshtest.pfx");

            IWebKeyConverter converters = WebKeyConverterFactory.CreateConverterChain();
            var webKey = converters.ConvertKeyFromFile(new FileInfo(File.Exists(consolePath) ? consolePath : vsPath), password.ConvertToSecureString());

            Assert.True(webKey.HasPrivateKey());
            Assert.True(webKey.IsValid());
            Assert.Equal(webKey.Kty, JsonWebKeyType.Rsa);
        }
        public void GetWebKeyFromByok()
        {
            Random rnd = new Random();

            byte[] byokBlob = new byte[100];
            rnd.NextBytes(byokBlob);
            string tempPath = Path.GetTempFileName() + ".byok";

            File.WriteAllBytes(tempPath, byokBlob);
            IWebKeyConverter converters = WebKeyConverterFactory.CreateConverterChain();
            var webKey = converters.ConvertKeyFromFile(new FileInfo(tempPath), null);

            Assert.True(webKey.T.SequenceEqual(byokBlob));
            Assert.Equal(webKey.Kty, JsonWebKeyType.RsaHsm);
        }
Example #4
0
 public PfxWebKeyConverter(IWebKeyConverter next = null)
 {
     this.next = next;
 }
 public PfxWebKeyConverter(IWebKeyConverter next = null)
 {
     this.next = next;
 }
Example #6
0
 public ByokWebKeyConverter(IWebKeyConverter next = null)
 {
     this.next = next;
 }
 public ByokWebKeyConverter(IWebKeyConverter next = null)
 {
     this.next = next;
 }