x509certificate2

Encrypt data with X509 certificate's private key in UWP

拟墨画扇 提交于 2019-12-11 14:31:58
问题 I'm displaying to the user every available certificates in his personal store, fetched with the following method : public List<X509Certificate2> GetPersonalCertificates() { var certificates = new List<X509Certificate2>(); using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser)) { store.Open(OpenFlags.MaxAllowed); foreach (var certificate in store.Certificates) { if (certificate != null && certificate.HasPrivateKey) { certificates.Add(certificate); } } } return certificates;

How to proper validate SSL certificate with X509Certificate2 on Mono and multiple platforms

点点圈 提交于 2019-12-11 13:40:14
问题 I have to validate several SSL certificates in a none-browser application for HttpRequests and websocket connections which should run on IOS, Android and Linux. When a connection via HTTPS happens I receive an array of X509Certificate2 objects where the bottom one is the server certificate and the most top one the root CA (hopefully). As an example, when I connect to https://google.com I receive 3 X509Certificate2 with the following SubjectName.Name : 0 : "CN=google.com, O=Google Inc, L

OpenIddict error with AddSigningCertificate

耗尽温柔 提交于 2019-12-11 10:15:56
问题 I am trying to signin certificate (OpenIddict), but I get error when trying with thumbprint: options.AddSigningCertificate(Configuration["Certificate"]/* db b9 12 .... 22 */); and the error: Application startup exception: System.Security.Cryptography.CryptographicException: OpenCSP failed with error code 2148073494. in this line: app.UseOpenIddict(); If I tried with X509Certificate2 I also get error: var cert = new X509Certificate2(Configuration["Certificate"]/*path to file.cer*/); options

SignedData giving Invalid algorithm specified.exception

自作多情 提交于 2019-12-11 08:04:23
问题 I tried to sign and valid my signed data using myCert.pfx file private and public key. But while signing the data I am getting " Invalid algorithm specified." exception .Net framework we are using is 4.5 and the code is as below public static void CallMainMethod() { string str = "Sign and verify the data"; X509Certificate2 certificate = LoadPrivateKey(); byte[] hashBytes = GetDataHash(str); byte[] signature = GetDigitalSignature(hashBytes); } private static X509Certificate2 LoadPrivateKey() {

RSA Encryption and Decryption with X509certificate2

倾然丶 夕夏残阳落幕 提交于 2019-12-11 06:36:21
问题 So, what I need is next: Create certifiactes for development, get one for the client and one for server Retrieve password through API that is encoded from client and decode it on server Now, I managed to create certifiactes following this link. The girl there gave step by step instructions on how to get self signed certifiactes, put them in store, etc... Now, the part I'm having problem with: I've managed to encrypt my data using this code: public static string Encrypt(string

Extract public key from certificate x509

馋奶兔 提交于 2019-12-11 06:02:09
问题 I am looking for a way to extract public key from certificate x509 (PEM format) in javascript like this one: openssl x509 -in cert.cer -pubkey -noout > pub.txt 回答1: You need something that can parse ASN.1 structure. You could use pkijs. Demo can be found here 回答2: var cert = forge.pki.certificateFromPem(pem); var pem = forge.pki.publicKeyToPem(cert.publicKey) Thanks halloulaguesmi. This seems to be working perfectly. 来源: https://stackoverflow.com/questions/44675333/extract-public-key-from

.NET Core X509Certificate2.PrivateKey throws nte_bad_keyset error

徘徊边缘 提交于 2019-12-11 05:47:17
问题 When trying to get a X509Certificate2 object from the X509Store using the following code: private X509Certificate2 GetKey() { try { X509Store store = new X509Store("WebHosting", StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); var collection = store.Certificates.Find(X509FindType.FindBySubjectName, "xxxxxxx", true); if (collection.Count == 0) { throw new Exception("No keys matched"); } if (collection.Count > 1) { StringBuilder sb = new StringBuilder(); sb.Append("More than 1 key

Malformed reference element signing a xml file of bills

人走茶凉 提交于 2019-12-11 05:38:57
问题 I'm developing a program to digitally sign invoices in xml. I followed this guide https://www.profissionaisti.com.br/2010/07/assinando-digitalmente-um-xml-usando-c/#comment-197297. However, i'm getting an error Malformed reference element. The code is : static void Main(string[] args) { //open certificates of current user var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); //Open screen to choose certificate var selectedCertificate =

Signing a json document or string with x509 certificate

℡╲_俬逩灬. 提交于 2019-12-11 03:52:50
问题 How to signing a json document or string with x509 certificate? public static void fund() { string filePath = @"C:\Users\VIKAS\Desktop\Data.xml"; //Read the file XmlDocument xmlDoc = new XmlDocument(); XElement ele = XElement.Load(filePath); String Xml = ele.ToString(); xmlDoc.LoadXml(Xml); string signature = SignedXMLCert(xmlDoc); bool verified = ValidateSignature(signature); } public static string SignedXMLCert(XmlDocument xmlDoc) { string startupPath = AppDomain.CurrentDomain.BaseDirectory

PrivateKey threw an exception of type System.Security.Cryptography.CryptographicException

孤人 提交于 2019-12-11 01:41:55
问题 I'm trying to use self-signed certificate using the following code: X509Certificate2 cert = ToCertificate("CN=localhost"); public static X509Certificate2 ToCertificate(this string subjectName, StoreName name = StoreName.My, StoreLocation location = StoreLocation.LocalMachine ) { X509Store store = new X509Store(name, location); store.Open(OpenFlags.ReadOnly); try { var cert = store.Certificates.OfType<X509Certificate2>().FirstOrDefault(c => c.Subject.Equals(subjectName, StringComparison