Эта страница является
переводом страницы
Encryption. Перевод выполнен на 100%.
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)
| on the input |
value |
description
|
| encryption_type |
IR.ENCRYPTION_RSA, IR.ENCRYPTION_AES |
type: Object Type of encryption.
|
| key_size |
32(256 bit), 64(512 bit), 128(1024 bit), 256(2048 bit), 512(4096 bit) |
type: Number The size of a key in bytes.
|
| key |
"60,25,57,21,96,..." |
type: String Key.
|
| is_public |
true |
type: Boolean true - a public key, false - a private key.
|
| AES_object |
l_AESInit = {"Vector": "56,2e,17, ...", "Key": "60,25,57, ..."} |
type: Object Encryption data.
|
| on the output |
|
|
| Object |
[object EnctyptionPrototype] |
type: Object Encryption object.
|
//////////////AES encryption object.////////////////
//CBC:
//Creating an object with data:
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"
}
//Creating an encryption object
var AES = IR.CreateEncryption(IR.ENCRYPTION_AES, l_AESInit);
//ECB:
//Creating an object with data:
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
}
//Creating an encryption object
var AES = IR.CreateEncryption(IR.ENCRYPTION_AES, l_AESInit);
//////////////RSA encryption object.////////////////
//Creating an encryption object with a 128-byte key:
var RSA_1 = IR.CreateEncryption(IR.ENCRYPTION_RSA, 128);
var public_key = RSA_1.GetPublicKey(); // getting a public key
//Creating an encyrption object with the help of a public key:
var RSA_2 = IR.CreateEncryption(IR.ENCRYPTION_RSA, public_key, true);
.Encode()
Encrypt a string or data array.
Syntax
IR.CreateEncryption(param).Encode(data, resultType, inputType)
| on the input |
value |
description
|
| data |
"3,0,0,0,0, ..." |
type: String / Array Encryption data.
|
| resultType |
IR.RESULT_TYPE_ARRAY, IR.RESULT_TYPE_BASE64_STRING* |
type: String / Array Type of encrypted value.
|
| inputType** |
IR.INPUT_TYPE_BYTE_STRING, IR.INPUT_TYPE_BASE64_STRING |
type: String Type of parameter data.
|
| on the output |
|
|
| EncryptedData |
"246,75,186,52,183, ..." |
type: String / Array Encrypted data.
|
// Encrype data with base64 result
var encode_base64 = RSA_2.Encode(data, IR.RESULT_TYPE_BASE64_STRING);
IR.Log("BASE64 ENCODE: " + encode_base64);
* You can get a string in the Base64 format not to lose data.
**Active only with a data string.
.Decode()
Decrypt a string or data array.
Syntax
EncryptedData.Decode(data, resultType, inputType)
| on the 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 Type of encrypted value.
|
| inputType** |
IR.INPUT_TYPE_BYTE_STRING, IR.INPUT_TYPE_BASE64_STRING |
type: String Type of parameter data.
|
| on the output |
|
|
| DecryptedData |
"3,0,0,0,0, ..." |
type: String / Array Decrypted data.
|
// Decrypt encode_base64 with a string result:
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);
* You can get a string in the Base64 format not to lose data.
**Active only with a data string.
.GetPublicKey()
Get a public key.
Syntax
EncryptedData.GetPublicKey()
| EncryptedData
|
"246,75,186,52,183, ..."
|
type: String / Array Encrypted data.
|
| PublicKey
|
"60,25,57,21,96,..."
|
type: String A public key.
|
Sample
// Initialization of an encryption object.
var RSA_1 = IR.CreateEncryption(IR.ENCRYPTION_RSA, 128);
//Getting a public key
var public_key = RSA_1.GetPublicKey();
IR.Log("public key: " + public_key);
This method works only with RSA encryption.