GlideEncrypter in scoped app

Harshal Sonawa1
Kilo Guru

GlideEncrypter in scoped app?

Create a new script include in the global context that takes your string value as a parameter and then use GlideEncrypter to do the work for you inside the script include function. You then return the the encrypted value to your calling script. In order to call the new include from a scope application script you can use similar to the following:

var encryptmypwd = new global.myEncrypterInclude(); //Note the global prefix
var encryptedpwd = encryptmypwd.encryptPwd("myrandompasswordstring");

 

encryptPwd above is the function inside my new script include that uses GlideEncrypter to encrypt for me

 

 

CAN SOMEONE help me with this? I want this to be implemented?

here is the link for more information on above mentioned description.

https://community.servicenow.com/community?id=community_question&sys_id=23fdc7addb9cdbc01dcaf3231f9619b6

1 ACCEPTED SOLUTION

John Dewhurst
Kilo Guru

Create this script include in the global scope open to all scopes...

var Encrypter = Class.create();
Encrypter.prototype = {
    initialize: function(key) {
		this.ge = new GlideEncrypter(key); 
    },
	
	encrypt: function(str){
		return this.ge.encrypt(str);
	},
	
	decrypt: function(str){
		return this.ge.decrypt(str);
	},

    type: 'Encrypter'
};

And you can use it like this in any scope...

var e = new global.Encrypter("abcdefghijklmnopqrstuvwx");
var secret = e.encrypt("test");
gs.info(secret); // => Zjem9344FZk=
gs.info(e.decrypt(secret)); // => test

Tested in background scripts from scoped app and this works fine (in Tokyo).

View solution in original post

4 REPLIES 4

John Dewhurst
Kilo Guru

Create this script include in the global scope open to all scopes...

var Encrypter = Class.create();
Encrypter.prototype = {
    initialize: function(key) {
		this.ge = new GlideEncrypter(key); 
    },
	
	encrypt: function(str){
		return this.ge.encrypt(str);
	},
	
	decrypt: function(str){
		return this.ge.decrypt(str);
	},

    type: 'Encrypter'
};

And you can use it like this in any scope...

var e = new global.Encrypter("abcdefghijklmnopqrstuvwx");
var secret = e.encrypt("test");
gs.info(secret); // => Zjem9344FZk=
gs.info(e.decrypt(secret)); // => test

Tested in background scripts from scoped app and this works fine (in Tokyo).

Hi @John Dewhurst ,

Thank You So Much. Its working.

I have few questions which encryption algo does it uses AES-128 or AES-256.

 

var e = new global.Encrypter("abcdefghijklmnopqrstuvwx");

What is this parameter passed to encrypter function? Is it secret key? 

Can we pass some different value? and why its not complete abcdef....xyz , I can see yz is missing. Can you help me to understand this.

Yeah that is the encryption key, it has apparently to be 24 characters long, it can be omitted in which case it uses a default key.

It's all documented here

It uses tripled DES encryption according to that, cryptography is out of my wheelhouse but that is described here

Understood very well. Thank You So Much John!! :)✌