示例#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;
 }
示例#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);
 }
        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);
        }