internal JsonWebKey CreateWebKeyFromFile() { FileInfo keyFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.KeyFilePath)); if (!keyFile.Exists) { throw new FileNotFoundException(string.Format(KeyVaultProperties.Resources.KeyFileNotFound, this.KeyFilePath)); } var converterChain = WebKeyConverterFactory.CreateConverterChain(); return converterChain.ConvertKeyFromFile(keyFile, KeyFilePassword); }
internal Track2Sdk.JsonWebKey CreateTrack2WebKeyFromFile() { FileInfo keyFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.KeyFilePath)); if (!keyFile.Exists) { throw new FileNotFoundException(string.Format(Resources.KeyFileNotFound, this.KeyFilePath)); } var converterChain = WebKeyConverterFactory.CreateConverterChain(); return(converterChain.ConvertToTrack2SdkKeyFromFile(keyFile, KeyFilePassword)); }
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); }
internal JsonWebKey CreateWebKeyFromFile() { ValidateEcParameters(); FileInfo keyFile = new FileInfo(this.GetUnresolvedProviderPathFromPSPath(this.KeyFilePath)); if (!keyFile.Exists) { throw new FileNotFoundException(string.Format(Resources.KeyFileNotFound, this.KeyFilePath)); } var converterChain = WebKeyConverterFactory.CreateConverterChain(); var converterExtraInfo = new WebKeyConverterExtraInfo() { KeyType = KeyType, CurveName = CurveName }; return(converterChain.ConvertKeyFromFile(keyFile, KeyFilePassword, converterExtraInfo)); }