Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Aes256Encrypt.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 Aes256Encrypt(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(Aes256Encrypt);
64
68 public override string[] DefaultArgumentNames => new string[] { "Content", "Key", "IV", "CipherMode", "PaddingMode" };
69
77 {
78 if (!(Arguments[0].AssociatedObjectValue is byte[] Data))
79 throw new ScriptRuntimeException("Data to encrypt must be binary (i.e. an array of bytes).", this);
80
81 if (!(Arguments[1].AssociatedObjectValue is byte[] Key))
82 throw new ScriptRuntimeException("Key to use for encryption must be binary (i.e. an array of bytes).", this);
83
84 if (!(Arguments[2].AssociatedObjectValue is byte[] IV))
85 throw new ScriptRuntimeException("Initiation Vector to use for encryption must be binary (i.e. an array of bytes).", this);
86
87 int c = Arguments.Length;
88 CipherMode CipherMode = c <= 3 ? CipherMode.CBC : this.ToEnum<CipherMode>(Arguments[3]);
89 PaddingMode PaddingMode = c <= 4 ? PaddingMode.PKCS7 : this.ToEnum<PaddingMode>(Arguments[4]);
90
91 using (Aes Aes = Aes.Create())
92 {
93 Aes.BlockSize = 128;
94 Aes.KeySize = 256;
95 Aes.Mode = CipherMode;
96 Aes.Padding = PaddingMode;
97
98 using (ICryptoTransform Transform = Aes.CreateEncryptor(Key, IV))
99 {
100 byte[] Encrypted = Transform.TransformFinalBlock(Data, 0, Data.Length);
101 return new ObjectValue(Encrypted);
102 }
103 }
104 }
105 }
106}
Aes256Encrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, ScriptNode CipherMode, ScriptNode PaddingMode, int Start, int Length, Expression Expression)
AES Encryption
override string[] DefaultArgumentNames
Default Argument names
Aes256Encrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, int Start, int Length, Expression Expression)
AES Encryption
Aes256Encrypt(ScriptNode Content, ScriptNode Key, ScriptNode IV, ScriptNode CipherMode, int Start, int Length, Expression Expression)
AES Encryption
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