Пример #1
0
 public void Archive(Stream outputStream, ProtectedKey keyToBeArchived, string passphrase)
 {
     byte[] bytes = BitConverter.GetBytes(0x10e1);
     byte[] salt = this.GenerateSalt();
     byte[] buffer = this.GetEncryptedKey(keyToBeArchived, passphrase, salt);
     outputStream.Write(bytes, 0, bytes.Length);
     outputStream.Write(salt, 0, salt.Length);
     outputStream.Write(buffer, 0, buffer.Length);
 }
Пример #2
0
 public SymmetricAlgorithmProvider(Type algorithmType, ProtectedKey key)
 {
     if (algorithmType == null)
     {
         throw new ArgumentNullException("algorithmType");
     }
     if (!typeof(SymmetricAlgorithm).IsAssignableFrom(algorithmType))
     {
         throw new ArgumentException("The type must be of type SymmetricAlgorithm.", "algorithmType");
     }
     this.algorithmType = algorithmType;
     this.key = key;
 }
Пример #3
0
 byte[] GetEncryptedKey(ProtectedKey keyToBeArchived, string passphrase, byte[] salt)
 {
     byte[] buffer2;
     byte[] decryptedKey = keyToBeArchived.DecryptedKey;
     try
     {
         buffer2 = this.EncryptKeyForArchival(decryptedKey, passphrase, salt);
     }
     finally
     {
         CryptographyUtility.ZeroOutBytes(decryptedKey);
     }
     return buffer2;
 }
Пример #4
0
 byte[] GetEncryptedKey(ProtectedKey keyToBeArchived, string passphrase, byte[] salt)
 {
     byte[] buffer2;
     byte[] decryptedKey = keyToBeArchived.DecryptedKey;
     try
     {
         buffer2 = this.EncryptKeyForArchival(decryptedKey, passphrase, salt);
     }
     finally
     {
         CryptographyUtility.ZeroOutBytes(decryptedKey);
     }
     return(buffer2);
 }
Пример #5
0
 public SymmetricCryptographer(Type algorithmType, ProtectedKey key)
 {
     if (algorithmType == null)
     {
         throw new ArgumentNullException("algorithmType");
     }
     if (!typeof(SymmetricAlgorithm).IsAssignableFrom(algorithmType))
     {
         throw new ArgumentException("The type must be of type SymmetricAlgorithm.", "algorithmType");
     }
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     this.key       = key;
     this.algorithm = GetSymmetricAlgorithm(algorithmType);
 }
Пример #6
0
        ProtectedKey GenerateKey(SymmetricAlgorithm algorithm, DataProtectionScope dataProtectionScope)
        {
            ProtectedKey key;

            byte[] plaintextKey = this.GenerateUnprotectedKey(algorithm);
            try
            {
                key = ProtectedKey.CreateFromPlaintextKey(plaintextKey, dataProtectionScope);
            }
            finally
            {
                if (plaintextKey != null)
                {
                    CryptographyUtility.ZeroOutBytes(plaintextKey);
                }
            }
            return(key);
        }
Пример #7
0
 public static void ArchiveKey(Stream outputStream, ProtectedKey keyToArchive, string passphrase)
 {
     IKeyWriter writer = new KeyReaderWriter();
     writer.Archive(outputStream, keyToArchive, passphrase);
 }
Пример #8
0
 public void Write(Stream outputStream, ProtectedKey key)
 {
     this.WriteVersionNumber(outputStream, 0x10e1);
     this.WriteEncryptedKey(outputStream, key);
 }
Пример #9
0
        public static void Write(Stream outputStream, ProtectedKey key)
        {
            IKeyWriter writer = new KeyReaderWriter();

            writer.Write(outputStream, key);
        }
Пример #10
0
 void WriteEncryptedKey(Stream outputStream, ProtectedKey key)
 {
     outputStream.Write(key.EncryptedKey, 0, key.EncryptedKey.Length);
 }
Пример #11
0
 public HashCryptographer(Type algorithmType, ProtectedKey protectedKey)
     : this(algorithmType)
 {
     this.key = protectedKey;
 }
Пример #12
0
 public HashCryptographer(Type algorithmType, ProtectedKey protectedKey) : this(algorithmType)
 {
     this.key = protectedKey;
 }
Пример #13
0
 public static void Write(Stream outputStream, ProtectedKey key)
 {
     IKeyWriter writer = new KeyReaderWriter();
     writer.Write(outputStream, key);
 }
Пример #14
0
        public static void ArchiveKey(Stream outputStream, ProtectedKey keyToArchive, string passphrase)
        {
            IKeyWriter writer = new KeyReaderWriter();

            writer.Archive(outputStream, keyToArchive, passphrase);
        }
Пример #15
0
 public ProtectedKey Read(Stream protectedKeyStream, DataProtectionScope protectionScope)
 {
     this.ValidateKeyVersion(protectedKeyStream);
     return(ProtectedKey.CreateFromEncryptedKey(this.ReadEncryptedKey(protectedKeyStream), protectionScope));
 }
Пример #16
0
 void WriteEncryptedKey(Stream outputStream, ProtectedKey key)
 {
     outputStream.Write(key.EncryptedKey, 0, key.EncryptedKey.Length);
 }
Пример #17
0
 public void Write(Stream outputStream, ProtectedKey key)
 {
     this.WriteVersionNumber(outputStream, 0x10e1);
     this.WriteEncryptedKey(outputStream, key);
 }
Пример #18
0
        public static void Write(Stream outputStream, byte[] encryptedKey, DataProtectionScope dpapiProtectionScope)
        {
            ProtectedKey key = ProtectedKey.CreateFromEncryptedKey(encryptedKey, dpapiProtectionScope);

            Write(outputStream, key);
        }