예제 #1
0
        public void Persist(TKey thisKey, AsymmetricKeyFilePersisterOptions withOptions)
        {
            {
                // Write private key
                var privateKeyXmlPoco = new TKeyXmlPoco();
                _pocoMapper.Map(thisKey, privateKeyXmlPoco);
                var toWrite = _serializationUtils.Serialize(privateKeyXmlPoco);

                var fileWriterOptions = new TFileWriterOptions()
                {
                    Contents = toWrite,
                    Encoding = _serializationUtils.GetUsedEncoding(),
                    Path     = withOptions.NewPrivateKeyFullFilePath,
                    OverwriteIfFileExists = withOptions.OverwriteFileIfExists
                };
                _writer.Write(fileWriterOptions);
            }

            {
                // Write public key
                var publicKeyXmlPoco = new TKeyXmlPoco();
                _pocoMapper.Map(GetPublicKey(thisKey), publicKeyXmlPoco);
                var toWrite = _serializationUtils.Serialize(publicKeyXmlPoco);

                var fileWriterOptions = new TFileWriterOptions()
                {
                    Contents = toWrite,
                    Encoding = _serializationUtils.GetUsedEncoding(),
                    Path     = withOptions.NewPublicKeyFullFilePath,
                    OverwriteIfFileExists = withOptions.OverwriteFileIfExists
                };
                _writer.Write(fileWriterOptions);
            }
        }
예제 #2
0
        public void Save(EnvCryptDat data, DatToFileSaverOptions fileSaverOptions)
        {
            if (fileSaverOptions == null ||
                string.IsNullOrWhiteSpace(fileSaverOptions.DestinationFilePath))
            {
                throw new ArgumentException("destination file path cannot be empty");
            }

            var xmlPoco = _pocoToXmlMapper.Map(data);
            var xmlStr  = _serializationUtils.Serialize(xmlPoco);

            var fileWriterOptions = new StringToFileWriterOptions()
            {
                Contents = xmlStr,
                Encoding = _serializationUtils.GetUsedEncoding(),
                Path     = fileSaverOptions.DestinationFilePath,
                OverwriteIfFileExists = true
            };

            _fileWriter.Write(fileWriterOptions);
        }