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;
2using System.Security.Cryptography;
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 using (Aes Aes = Aes.Create())
95 {
96 Aes.BlockSize = 128;
97 Aes.KeySize = 256;
98 Aes.Mode = CipherMode;
99 Aes.Padding = PaddingMode;
100
101 using (ICryptoTransform Transform = Aes.CreateDecryptor(Key, IV))
102 {
103 byte[] Encrypted = Transform.TransformFinalBlock(Data, 0, Data.Length);
104 return new ObjectValue(Encrypted);
105 }
106 }
107 }
108 }
109}
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
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Class managing a script expression.
Definition: Expression.cs:39
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:20