Beispiel #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);
 }
 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;
 }
Beispiel #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;
 }
Beispiel #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);
 }
Beispiel #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);
 }
        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);
        }
Beispiel #7
0
 public static void ArchiveKey(Stream outputStream, ProtectedKey keyToArchive, string passphrase)
 {
     IKeyWriter writer = new KeyReaderWriter();
     writer.Archive(outputStream, keyToArchive, passphrase);
 }
Beispiel #8
0
 public void Write(Stream outputStream, ProtectedKey key)
 {
     this.WriteVersionNumber(outputStream, 0x10e1);
     this.WriteEncryptedKey(outputStream, key);
 }
Beispiel #9
0
        public static void Write(Stream outputStream, ProtectedKey key)
        {
            IKeyWriter writer = new KeyReaderWriter();

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

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

            Write(outputStream, key);
        }