public static EncryptedLoaderFrame Create(byte[] unencryptedData)
        {
            int length = unencryptedData.Length;

            if (length % BootLoaderCryptoAlgorithm.DecryptedBlockSize != 0)
            {
                throw new ArgumentException("Unencrypted data is not a multiple of 50 byte block size.");
            }

            int blockCount = length / BootLoaderCryptoAlgorithm.DecryptedBlockSize;

            if (blockCount == 0 || blockCount > 5)
            {
                throw new ArgumentException("Unencrypted data must be 1 to 5 blocks of 50 bytes.");
            }

            EncryptedLoaderFrame frame = new EncryptedLoaderFrame(blockCount);

            frame.Encrypt(unencryptedData);

            return(frame);
        }
        public static EncryptedLoaderFrame Load(Stream encryptedStream)
        {
            byte header = (byte)encryptedStream.ReadByte();

            if (!IsValidHeader(header))
            {
                throw new ArgumentException("Invalid header information in stream.");
            }

            int frameLength = GetBlockCount(header) * BootLoaderCryptoAlgorithm.EncryptedBlockSize;

            byte[] data      = new byte[frameLength];
            int    bytesRead = encryptedStream.Read(data, 0, frameLength);

            if (bytesRead != frameLength)
            {
                throw new ArgumentException("Stream does not contain enough data.");
            }

            EncryptedLoaderFrame frame = new EncryptedLoaderFrame(data);

            return(frame);
        }