Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Aes256Decrypt.cs
1using System;
7
9{
14 {
25 : base(new ScriptNode[] { Content, Key, IV }, argumentTypes3Normal, Start, Length, Expression)
26 {
27 }
28
40 : base(new ScriptNode[] { Content, Key, IV, CipherMode }, argumentTypes4Normal, Start, Length, Expression)
41 {
42 }
43
55 public Aes256Decrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, ScriptNode CipherMode, ScriptNode PaddingMode, int Start, int Length, Expression Expression)
56 : base(new ScriptNode[] { Content, Key, IV, CipherMode, PaddingMode }, argumentTypes5Normal, Start, Length, Expression)
57 {
58 }
59
63 public override string FunctionName => nameof(Aes256Decrypt);
64
68 public override string[] DefaultArgumentNames => new string[] { "Content", "Key", "IV", "CipherMode", "PaddingMode" };
69
77 {
78 byte[] Data = Arguments[0].AssociatedObjectValue as byte[];
79 if (Data is null)
80 throw new ScriptRuntimeException("Data to decrypt must be binary (i.e. an array of bytes).", this);
81
82 byte[] Key = Arguments[1].AssociatedObjectValue as byte[];
83 if (Key is null)
84 throw new ScriptRuntimeException("Key to use for decryption must be binary (i.e. an array of bytes).", this);
85
86 byte[] IV = Arguments[2].AssociatedObjectValue as byte[];
87 if (IV is null)
88 throw new ScriptRuntimeException("Initiation Vector to use for decryption must be binary (i.e. an array of bytes).", this);
89
90 int c = Arguments.Length;
91 CipherMode CipherMode = c <= 3 ? CipherMode.CBC : this.ToEnum<CipherMode>(Arguments[3]);
92 PaddingMode PaddingMode = c <= 4 ? PaddingMode.PKCS7 : this.ToEnum<PaddingMode>(Arguments[4]);
93
94 return new ObjectValue(Decrypt(Data, Key, IV, CipherMode, PaddingMode));
95 }
96
106 public static byte[] Decrypt(byte[] Data, byte[] Key, byte[] IV, CipherMode CipherMode = CipherMode.CBC, PaddingMode PaddingMode = PaddingMode.PKCS7)
107 {
108 if (Data is null)
109 throw new ArgumentNullException(nameof(Data));
110
111 if (Key is null)
112 throw new ArgumentNullException(nameof(Key));
113
114 if (IV is null)
115 throw new ArgumentNullException(nameof(IV));
116
117 using (Aes Aes = Aes.Create())
118 {
119 Aes.BlockSize = 128;
120 Aes.KeySize = 256;
121 Aes.Mode = CipherMode;
122 Aes.Padding = PaddingMode;
123
124 using (ICryptoTransform Transform = Aes.CreateDecryptor(Key, IV))
125 {
126 return Transform.TransformFinalBlock(Data, 0, Data.Length);
127 }
128 }
129 }
130 }
131}
Aes256Decrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, ScriptNode CipherMode, int Start, int Length, Expression Expression)
AES Decryption
Aes256Decrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, ScriptNode CipherMode, ScriptNode PaddingMode, int Start, int Length, Expression Expression)
AES Decryption
override string[] DefaultArgumentNames
Default Argument names
Aes256Decrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, int Start, int Length, Expression Expression)
AES Decryption
static byte[] Decrypt(byte[] Data, byte[] Key, byte[] IV, CipherMode CipherMode=CipherMode.CBC, PaddingMode PaddingMode=PaddingMode.PKCS7)
Performs AES decryption of data.
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Class managing a script expression.
Definition: Expression.cs:41
Base class for multivariate funcions.
static readonly ArgumentType[] argumentTypes3Normal
Three normal parameters.
static readonly ArgumentType[] argumentTypes4Normal
Four normal parameters.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes5Normal
Five normal parameters.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21