Example #1
0
        public void SetManifestKey(byte[] wrappedKeyData)
        {
            if (wrappedKeyData is null)
            {
                throw new ArgumentNullException(nameof(wrappedKeyData));
            }

            _logger.LogInformation("Retrieving manifest wrapped encryption key");
            _wrappedManifestKey = WrappedKeyReader.Read(wrappedKeyData);
        }
Example #2
0
        public static WrappedKey Read(byte[] wrappedKeyData)
        {
            if (wrappedKeyData is null)
            {
                throw new ArgumentNullException(nameof(wrappedKeyData));
            }

            WrappedKey result = default;

            if (wrappedKeyData.Length == 44)
            {
                result = new WrappedKey
                {
                    Unknown = wrappedKeyData.AsSpan(0, 4).ToArray(),
                    Key     = wrappedKeyData.AsSpan(4, 40).ToArray(),
                };
            }

            return(result);
        }
Example #3
0
        private WrappedKey ReadEncryptionKey(BinaryReader reader)
        {
            const int PrefixLength = 4;

            WrappedKey result = default;

            int size = reader.ReadUInt16BigEndian();

            if (size != 0xFFFF && size > PrefixLength)
            {
                int keySize = size - PrefixLength;

                result = new WrappedKey
                {
                    Unknown = reader.ReadBytes(PrefixLength),
                    Key     = reader.ReadBytes(keySize),
                };
            }

            return(result);
        }
Example #4
0
        public void DecryptFile(string inputFile, string outputFile, WrappedKey wrappedKey, ProtectionClass protectionClass, bool overwrite)
        {
            var key = UnwrapKey(wrappedKey, _classKeys, protectionClass);

            DecryptFileCore(inputFile, outputFile, key, overwrite);
        }
Example #5
0
        public static byte[] UnwrapKey(WrappedKey item, IReadOnlyDictionary <ProtectionClass, byte[]> classKeys, ProtectionClass protectionClass)
        {
            var kek = classKeys[protectionClass];

            return(KeyWrapAlgorithm.UnwrapKey(kek, item.Key));
        }
Example #6
0
        public static byte[] UnwrapKey(WrappedKey item, IReadOnlyDictionary <ProtectionClass, byte[]> classKeys)
        {
            var protectionClass = (ProtectionClass)item.Unknown[0];

            return(UnwrapKey(item, classKeys, protectionClass));
        }