Exemplo n.º 1
0
        public override void Load(Stream stream)
        {
            byte[] encryptedData;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                encryptedData = memoryStream.ToArray();
            }

            var base64Array = Encoding.UTF8.GetString(encryptedData).Split('.');

            var sessionKeyBlob = Convert.FromBase64String(base64Array[0]);

            var encryptedConfigData = Convert.FromBase64String(base64Array[1]);

            var sessionKey = SessionKeyContainer.FromBlob(sessionKeyBlob);

            var hybridDecryption = HybridDecryption.Create(_containerName, _signatureKey);

            var data = hybridDecryption.DecryptData(sessionKey, encryptedConfigData);

            using (MemoryStream memoryStream = new MemoryStream(data))
            {
                var configurationFileParser = new JsonConfigurationFileParser();
                this.Data = configurationFileParser.Parse(memoryStream);
            }
        }
Exemplo n.º 2
0
        public WhenDecryptingData()
        {
            _files = Directory.EnumerateFiles(WellKnownPaths.RSA_MACHINEKEYS)
                     .ToArray();

            var currentUser = WindowsIdentity.GetCurrent()
                              .Name;

            var signatureContainer  = "signature";
            var encryptionContainer = "encryption";

            var encryptionKey = RSAEncryption.CreateSecureContainer(encryptionContainer, currentUser);
            var signingKey    = RSAEncryption.CreateSecureContainer(signatureContainer, currentUser);

            var signaturePublicKey  = signingKey.ExportKey(false);
            var encryptionPublicKey = encryptionKey.ExportKey(false);

            _hybridEncryption = HybridEncryption.Create(encryptionPublicKey, signatureContainer);
            _hybridDecryption = HybridDecryption.Create(encryptionContainer, signaturePublicKey);
        }