public static void WriteToRegistry(string registryKey, string valueName, ISecurable value, RegKind regAs) { // the value should already be encrypted... RegistryValueKind kind; object writeThis = null; if (regAs == RegKind.String) { writeThis = Encoding.ASCII.GetString(value.GetBytes()); kind = RegistryValueKind.String; } else { writeThis = value.GetBytes(); kind = RegistryValueKind.Binary; } Registry.SetValue(registryKey, valueName, writeThis, kind); }
public ISecurable DecryptContent(ISecurable pStr) { byte[] sBytes = pStr.GetBytes(); byte[] content = StringSecurer.FromBase64BytesToBytes(sBytes); var cms = new EnvelopedCms(); cms.Decode(content); try { cms.Decrypt(); } catch (Exception ex) { throw new ProtectedStringDecryptionException(ex); } var pts = StringSecurer.FromBase64Bytes(cms.ContentInfo.Content); return(pts); }
public ISecurable EncryptString(ISecurable pts) { if (disposed) { throw new ObjectDisposedException("SecurityManager"); } if (this.Certificate == null) { throw new InvalidOperationException("The encryption certificate is still not set! Use the 'SetCertificate' method first."); } var cinfo = new ContentInfo(pts.GetBytes()); var cms = new EnvelopedCms(cinfo); var recipient = new CmsRecipient(this.Certificate); cms.Encrypt(recipient); var base64 = StringSecurer.ToBase64Securable(cms.Encode()); return(base64); }