예제 #1
0
        internal DFunction(byte[]  ask, bool encryption = true)
        {
            ArgumentThrow.IfLengthNot(ask, 16, "Only 16-bytes ASKs are valid.", nameof(ask));

            this.ASK        = ask;
            this.encryption = encryption;
        }
예제 #2
0
        public static byte[] ScrambledParcel(this EncryptedCKParcel parcel, byte[] key)
        {
            ArgumentThrow.IfNull(parcel, $"Invalid {typeof(EncryptedCKParcel).Name} to scramble. Parcel can not be null.", nameof(parcel));
            ArgumentThrow.IfLengthNot(key, 16, "Invalid key to scramble. Key buffer should be 16 bytes.", nameof(key));

            using (var aes = Aes.Create())
            {
                // aes.IV = null;
                aes.Key     = key;
                aes.Mode    = CipherMode.ECB;
                aes.Padding = PaddingMode.None;

                using (var encryptor = aes.CreateEncryptor())
                    using (var memoryStream = new MemoryStream())
                        using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                        {
                            cryptoStream.Write(parcel.Binary);

                            return(memoryStream.ToArray());
                        }
            }
        }
예제 #3
0
        public static byte[] UnscrambledParcel(this SKR1Payload payload, byte[] key)
        {
            ArgumentThrow.IfNull(payload, $"Invalid {typeof(SKR1Payload).Name} to unscramble. Payload can not be null.", nameof(payload));
            ArgumentThrow.IfLengthNot(key, 16, "Invalid key to unscramble. Key buffer should be 16 bytes.", nameof(key));

            using (var aes = Aes.Create())
            {
                aes.IV      = payload.IV;
                aes.Key     = key;
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.None;

                using (var decryptor = aes.CreateDecryptor())
                    using (var memoryStream = new MemoryStream())
                        using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Write))
                        {
                            cryptoStream.Write(payload.Parcel);

                            return(memoryStream.ToArray());
                        }
            }
        }
예제 #4
0
        public static byte[] ScrambledPayload(byte[] payload, byte[] iv, byte[] key)
        {
            ArgumentThrow.IfLengthNotMultiple(payload, 16, "Invalid payload to scramble. The buffer length should be multiple of 16.", nameof(payload));
            ArgumentThrow.IfLengthNot(iv, 16, "Invalid key to scramble. Key buffer should be 16 bytes.", nameof(iv));
            ArgumentThrow.IfLengthNot(key, 16, "Invalid key to scramble. Key buffer should be 16 bytes.", nameof(key));

            using (var aes = Aes.Create())
            {
                aes.IV      = iv;
                aes.Key     = key;
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.None;

                using (var encryptor = aes.CreateEncryptor())
                    using (var memoryStream = new MemoryStream())
                        using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                        {
                            cryptoStream.Write(payload);

                            return(memoryStream.ToArray());
                        }
            }
        }