Encryption
IR.CreateEncryption()
Create an encryption object.
Syntax
RSA:
IR.CreateEncryption(encryption_type, key_size)
IR.CreateEncryption(encryption_type, key, is_public)
AES:
IR.CreateEncryption(encryption_type, AES_object)
| Input | Value | Description |
|---|---|---|
| encryption_type | IR.ENCRYPTION_RSA IR.ENCRYPTION_AES | type: Object Encryption type |
| key_size | 32 (256 bits) 64 (512 bits) 128 (1024 bits) 256 (2048 bits) 512 (4096 bits) | type: Number Key size in bytes |
| key | "60,25,57,21,96,..." | type: String Key |
| is_public | true | type: Boolean true - public key, false - private key |
| AES_object | l_AESInit = "Vector": "56,2e,17, ..." "Key": "60,25,57, ..." | type: Object Encryption data |
| Output | ||
| Object | [object EnctyptionPrototype] | type: Object Encryption object |
//////////////Объект шифрования AES////////////////
//CBC:
//Создание объекта с данными:
var l_AESInit = {
"Vector": "56,2e,17,99,6d,09,3d,28,dd,b3,ba,69,5a,2e,6f,58",
"Key": "60,25,57,21,96,98,cd,10,cd,0b,44,00,03,7f,ba,6f"
}
//Создание объекта шифрования:
var AES = IR.CreateEncryption(IR.ENCRYPTION_AES, l_AESInit);
//ECB:
//Создание объекта с данными:
var l_AESInit = {
"Key": "60,25,57,21,96,98,cd,10,cd,0b,44,00,03,7f,ba,6f",
"Type": 1 // 1 = ENCRYPTION_AES_ECB, 0 = ENCRYPTION_AES_CBC
}
//Создание объекта шифрования:
var AES = IR.CreateEncryption(IR.ENCRYPTION_AES, l_AESInit);
//////////////Объект шифрования RSA////////////////
//Создание объекта шифрования с ключом размером 128 байт:
var RSA_1 = IR.CreateEncryption(IR.ENCRYPTION_RSA, 128);
var public_key = RSA_1.GetPublicKey(); // получение публичного ключа
//Создание объекта шифрования с помощью публичного ключа:
var RSA_2 = IR.CreateEncryption(IR.ENCRYPTION_RSA, public_key, true);
.Encode()
Encrypt a string or an array of data.
Syntax
IR.CreateEncryption(param).Encode(data, resultType, inputType)
| Input | Value | Description |
|---|---|---|
| data | "3,0,0,0,0, ..." | type: String/Array Data to encrypt |
| resultType | IR.RESULT_TYPE_ARRAY IR.RESULT_TYPE_BASE64_STRING* | type: String/Array Encrypted value type |
| inputType** | IR.INPUT_TYPE_BYTE_STRING IR.INPUT_TYPE_BASE64_STRING | type: String Type of the parameter data |
| Output | ||
| EncryptedData | "246,75,186,52,183, ..." | type: String/Array Encrypted data |
// Кодировать данные с результатом base64
var encode_base64 = RSA_2.Encode(data, IR.RESULT_TYPE_BASE64_STRING);
IR.Log("BASE64 ENCODE: " + encode_base64);
Note
- You can obtain a Base64 string to avoid losing data.
- Applies only if data is a string.
.Decode()
Decrypt a string or an array of data.
Syntax
EncryptedData.Decode(data, resultType, inputType)
| Input | Value | Description |
|---|---|---|
| data | "246,75,186,52,183, ..." | type: String/Array Encrypted data |
| resultType | IR.RESULT_TYPE_ARRAY IR.RESULT_TYPE_STRING IR.RESULT_TYPE_BASE64_STRING* | type: String/Array Decrypted value type |
| inputType** | IR.INPUT_TYPE_BYTE_STRING IR.INPUT_TYPE_BASE64_STRING | type: String Type of the parameter data |
| Output | ||
| DecryptedData | "3,0,0,0,0, ..." | type: String Array Decrypted data |
// Декодировать encode_base64 со строковым результатом:
var decode_string_1 = RSA_1.Decode(encode_base64, IR.RESULT_TYPE_STRING, IR.INPUT_TYPE_BASE64_STRING);
IR.Log("STRING DECODE_FROM_BASE64: " + decode_string_1);
Note
- You can obtain a Base64 string to avoid losing data.
- Applies only if data is a string.
.GetPublicKey()
Get the public key.
Syntax
EncryptedData.GetPublicKey()
| Input | Value | Description |
|---|---|---|
| EncryptedData | "246,75,186,52,183, ..." | type: String Encrypted data. / Array |
| Output | ||
| PublicKey | "60,25,57,21,96,..." | type: String Public key. |
Example
// Инициализация объекта шифрования:
var RSA_1 = IR.CreateEncryption(IR.ENCRYPTION_RSA, 128);
//Получение публичного ключа:
var public_key = RSA_1.GetPublicKey();
IR.Log("public key: " + public_key);
Notes
Tip
This method works only with RSA encryption.