5. Encrypting & Decrypting Strings with SAS-RCSby: saaiqSASLast Updated: 26/2/2025
In this section, we will demonstrate how to encrypt and decrypt Strings using the SAS-RCS
(Saaiq Abdulla Saeed's - Random Character Substitution) encryption algorithm - Text-level encryption.
This process requires key reference IDs, which are int values returned by key extraction methods.
A usage sample of the ROSET Java API is available on GitHub. You can view it
here (ROSET Java API Usage Sample).
To perform encryption or decryption with the ROSET API, you need a Dynamic Key reference ID and an int[] array of Static Key reference IDs. These reference IDs are used to identify the specific keys that have already been extracted onto memory.
Encrypt String
To encrypt Strings using SAS-RCS, you can call the method rcsTextEncrypt(int Dynamic_Key_ID, int[] Static_Key_IDs_Array, String data).
This method will return the SAS-RCS encrypted data as String.
Below is an example snippet of how to use this method to perform encryption.
// Key Extraction
int Dynamic_Key_ID = // extract Dynamic Key
int Static_Key_ID_1 = // extract Static Key 1
int Static_Key_ID_2 = // extract Static Key 2
int Static_Key_ID_3 = // extract Static Key 3
// Prepare Static Key Reference ID array
int[] Static_Key_IDs_Array = {Static_Key_ID_1, Static_Key_ID_2, Static_Key_ID_3};
// Set up 'Quick Processing' (OPTIONAL, BUT PREFERRED for performance)
boolean isSet = SAS_ROSET.setQuickProcessing(true, Dynamic_Key_ID, Static_Key_IDs_Array);
// Encrypt the String
String text_data = "Hello";
String encrypted_text_data = SAS_ROSET.rcsTextEncrypt(Dynamic_Key_ID, Static_Key_IDs_Array, text_data);
Decrypt Encrypted String
To decrypt a SAS-RCS encrypted String, use the method rcsTextDecrypt(int Dynamic_Key_ID, int[] Static_Key_IDs_Array, String encrypted_data). Below is an example of how to implement this decryption method.
// Key Extraction
int Dynamic_Key_ID = // extract Dynamic Key used for encryption
int Static_Key_ID_1 = // extract Static Key 1 used for encryption
int Static_Key_ID_2 = // extract Static Key 2 used for encryption
int Static_Key_ID_3 = // extract Static Key 3 used for encryption
// Prepare Static Key Reference ID array
int[] Static_Key_IDs_Array = {Static_Key_ID_1, Static_Key_ID_2, Static_Key_ID_3};
// Set up 'Quick Processing' (OPTIONAL, BUT RECOMMENDED for better performance)
boolean isSet = SAS_ROSET.setQuickProcessing(true, Dynamic_Key_ID, Static_Key_IDs_Array);
// Decrypt the Encrypted String
String encrypted_text_data = "üģ´=}ôzĤûêĘÓğ¿Ò¹čIìsYãÞγe";
String decrypted_text_data = SAS_ROSET.rcsTextDecrypt(Dynamic_Key_ID, Static_Key_IDs_Array, encrypted_text_data);
Please note that the order of Static Key reference IDs in the Static_Key_IDs_Array is important for successful decryption.