Author Topic: Encrypting and Decrypting the SAP Password Using WS  (Read 6373 times)

Sai Siddhartha

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 47
    • View Profile
Encrypting and Decrypting the SAP Password Using WS
« on: July 21, 2017, 07:36:21 AM »
Purpose:
We can encrypt and decrypt SAP password with a simple WS function using 'RC4 Encryption Algorithm'.

Usage:
If password is currently being saved in the 'SAP USER' table. It is saved by default in an unencrypted format. To encrypt the password, please do the following.

Encrypting the SAP Password:
1.   Create a new RC4 object as shown in the following example:
var crp = new system.rc4("12345678");
The value "12345678" Is the encryption key. This is optional -if you do not supply a key, the algorithm will use the Synactive default key.
2.   Create new variable containing the encrypted password as shown in the following example:
Var encryptedpwd = crp.crypt("Password");
3.   The password has now been encrypted.

Decrypting the SAP Password:
To decrypt  the password, you will need to create a RC4 object. Please see the instructions below.
1.   Create a new RC4 object as in the example below:
var decrypt = new system.rc4("12345678");
2.   Create new variable containing the decrypted password as shown in the following example:
Var decryptedpwd = crp.crypt(encryptedpwd);

Example functions:

You can use this function for Encryption.
function EncryptText(){
    var crp = new system.rc4("12345678");
    var Encryptedtext = crp.crypt(str);
    return Encryptedtext;
}

Function to decrypt password.
function DecryptText(){
    var crp = new system.rc4("12345678");
    var Decryptedtext = crp.crypt(Encryptedtext);
    return Decryptedtext;
}

Below example demonstrates the encrypting and decrypting of text using single liquid ui function
Liquid UI Code:
------------------------------------------------------------------------------------------------------------------------------------------
Script file :  SAPLSMTR_NAVIGATION.E0100.sjs
------------------------------------------------------------------------------------------------------------------------------------------
//pushbutton for calling function
pushbutton([10,15], "Encrypt & Decrypt PWD  ",{ "process":cryptText, "using":{ "z_crypt":z_password }});
//inputfield to show encrypted and decrypted text
inputfield( [4,9], "Password", [4,25],{ "name":"z_password", "size":32});
del("X[IMAGE_CONTAINER]");

//function to encrypt and decrypt provided text
function cryptText(param){

    set("V[crypt]",param.z_crypt);
    var crp = new system.rc4("12345678"); //key for encryption(optional)
    cryptedtext = crp.crypt(crypt);

    onscreen 'SAPLSMTR_NAVIGATION.0100'
         set("V[z_password]","&V[cryptedtext]"); // crypted text assigned to inputfield "password"
          enter('?');
}

See attachment for more information and screenshots