public string ToKeyFileString(bool publicOnly) { KeyFileStorage keyStorage; byte[] temporaryCspBlob; using (ICspProxy csp = CspFactory.GetProvider()) { if (publicOnly) { temporaryCspBlob = csp.PublicKeyBlob; } else { temporaryCspBlob = csp.KeyBlob; } keyStorage = new KeyFileStorage { KeyMaterial = temporaryCspBlob, ProviderType = GetType().ToString(), ContainsPrivateKey = !publicOnly && !csp.IsPublicOnly }; } return(JsonConvert.SerializeObject(keyStorage)); }
public string ToKeyFileString(bool publicOnly) { KeyFileStorage keyStorage; byte[] temporaryCspBlob; using (ICspProxy csp = CspFactory.GetProvider()) { if (publicOnly) { temporaryCspBlob = csp.PublicKeyBlob; } else { temporaryCspBlob = csp.KeyBlob; } keyStorage = new KeyFileStorage { KeyMaterial = temporaryCspBlob, ProviderType = GetType().ToString(), ContainsPrivateKey = !publicOnly && !csp.IsPublicOnly }; } /* * using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) * { * rsa.ImportCspBlob(CspBlob); * * if (publicOnly && !rsa.PublicOnly) * { * temporaryCspBlob = rsa.ExportCspBlob(false); * } * else * { * temporaryCspBlob = CspBlob; * } * * keyStorage = new KeyFileStorage * { * KeyMaterial = temporaryCspBlob, * ProviderType = GetType().ToString(), * ContainsPrivateKey = !publicOnly && !rsa.PublicOnly * }; * } */ return(JsonConvert.SerializeObject(keyStorage)); }