<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Decryption using &amp;quot;Glide Encrypter in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408530#M65456</link>
    <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;I am aware that GlideEncrypter is only available in Global scope.&lt;BR /&gt;That is why we are using Global in the verification we are doing now.&lt;/P&gt;
&lt;P&gt;Encryption with GlideEncrypter works fine.&lt;BR /&gt;However, only the decryption does not work as described above.&lt;/P&gt;
&lt;P&gt;Is there something I am missing?&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2022 08:04:39 GMT</pubDate>
    <dc:creator>Koki</dc:creator>
    <dc:date>2022-04-01T08:04:39Z</dc:date>
    <item>
      <title>Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408526#M65452</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to decrypt the value using the Business Rule shown below.&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/) {
	
	if (gs.hasRole('x_540069_sn21.passwdCanRead_2')) {
		
        var encrString = current.u_password_string;
		var decrString = '';
		
		var encr = new GlideEncrypter();
		
		decrString = encr.decrypt(encrString);
		
		current.u_password_string = decrString;
		current.u_passwdstring = '';	
		
	}
})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have checked the contents of "encrString" using "Script Debugger" as follows&lt;/P&gt;
&lt;P&gt;encrString: I+tYsVN4xvz5915A7/EDfg==&lt;/P&gt;
&lt;P&gt;I would like to decrypt this with the above Business Rule, but the executed value shows "undefined".&lt;/P&gt;
&lt;P&gt;What is wrong with my Business Rule?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 06:18:37 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408526#M65452</guid>
      <dc:creator>Koki</dc:creator>
      <dc:date>2022-04-01T06:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408527#M65453</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;to be honest, your code makes no sense, as I can only see that you decrypt the value at&amp;nbsp;field "u_password_string" and then set that decrypted value again on the same field.&lt;/P&gt;
&lt;P&gt;But in case your field "u_password_string" is a password2 field, you have to set the decrypted value via&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;current.setDisplayValue('u_password_string', decrString);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;BR /&gt;Maik&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 06:28:16 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408527#M65453</guid>
      <dc:creator>Maik Skoddow</dc:creator>
      <dc:date>2022-04-01T06:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408528#M65454</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;I don't quite understand, "decrString = encr.decrypt(encrString);" You mean you don't need to do anything after this?&lt;/P&gt;
&lt;P&gt;By the way, if I write "current.setDisplayValue('u_password_string', decrString);", it shows "undefined" and without description, it shows "I+tYsVN4xvz5915A7/EDfg==".&lt;/P&gt;
&lt;P&gt;Is decryption not working?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 06:46:11 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408528#M65454</guid>
      <dc:creator>Koki</dc:creator>
      <dc:date>2022-04-01T06:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408529#M65455</link>
      <description>&lt;P&gt;Koki,&lt;/P&gt;
&lt;P&gt;Probably not working because GlideEncrypter is only available in Global scope. To use it in Scoped application, would need to create a script include that is accessible from all application scope and call that&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 07:52:23 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408529#M65455</guid>
      <dc:creator>Hitoshi Ozawa</dc:creator>
      <dc:date>2022-04-01T07:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408530#M65456</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;I am aware that GlideEncrypter is only available in Global scope.&lt;BR /&gt;That is why we are using Global in the verification we are doing now.&lt;/P&gt;
&lt;P&gt;Encryption with GlideEncrypter works fine.&lt;BR /&gt;However, only the decryption does not work as described above.&lt;/P&gt;
&lt;P&gt;Is there something I am missing?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:04:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408530#M65456</guid>
      <dc:creator>Koki</dc:creator>
      <dc:date>2022-04-01T08:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408531#M65457</link>
      <description>&lt;P&gt;Script include in Global with "Accessbile from" set to "All application scopes" and "Client callable" unchecked. There's already OOTB script include names"EncryptUtil" so named it "EncryptUtil2".&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;var EncryptUtil2 = Class.create();
EncryptUtil2.prototype = {
    initialize: function() {
    },
    encryptText: function(text) {
        var encr = new GlideEncrypter();
        return encr.encrypt(text);
    },
    decryptText: function(text) {
        var encr = new GlideEncrypter();
        return encr.decrypt(text);
    },
    type: 'EncryptUtil2'
};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As an example, created 3 fields name "Clear text" (u_clear_text), "Encrypted String" (u_encrypted), "Decrypted String" (u_decrypted).&lt;/P&gt;
&lt;P&gt;Created Client script to encrypt value of "Clear text" and set it in "Encrypted String".&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var ajax = new GlideAjax('EncryptText');
    ajax.addParam('sysparm_name', 'encryptText');
    ajax.addParam('sysparm_text', newValue);
    ajax.getXMLAnswer(function(answer) {
        if (answer.length &amp;gt; 0) {
            g_form.setValue('u_encrypted', answer);
        }
    });
  }&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Script Include named "EncryptText" that's client callable.&lt;/P&gt;
&lt;PRE class="language-markup"&gt;&lt;CODE&gt;var EncryptText = Class.create();
EncryptText.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    encryptText: function() {
        var text = this.getParameter('sysparm_text');
        var encr = new GlideEncrypter();
        return encr.encrypt(text);
    },
    decryptText: function() {
        var text = this.getParameter('sysparm_text');
        var encr = new GlideEncrypter();
        return encr.decrypt(text);
    },
    type: 'EncryptText'
});&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Business rule:&lt;/P&gt;
&lt;PRE class="language-javascript"&gt;&lt;CODE&gt;(function executeRule(current, previous /*null when async*/ ) {
    try {
        var encr = new global.EncryptUtil2();
        var encrypted = current.u_encrypted;
        var decrypted = encr.decryptText(encrypted);
        current.u_decrypted = decrypted;
    } catch (e) {
        current.u_decrypted = e.message;
    }
})(current, previous);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Execution:&lt;/P&gt;
&lt;P&gt;Step 1: Enter value into Clear text. Encrypted String is set.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/145302iA7C9BF9BB34A484D/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Step 2. Save form. Decrypted text is set in Decrypted String&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="find_real_file.png"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/145306i462CC3A6C1BB65E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="find_real_file.png" alt="find_real_file.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:08:24 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408531#M65457</guid>
      <dc:creator>Hitoshi Ozawa</dc:creator>
      <dc:date>2022-04-01T08:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408532#M65458</link>
      <description>&lt;P&gt;BTW, I've found that decrypting a long text in Business Rule is returning encrypted text instead of decrypted text. Try entering shorter text to test to see that works.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 08:12:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408532#M65458</guid>
      <dc:creator>Hitoshi Ozawa</dc:creator>
      <dc:date>2022-04-01T08:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408533#M65459</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;I was able to confirm the operation by following the procedure you taught me.&lt;/P&gt;
&lt;P&gt;In conclusion, is it that the decryption could not be done well because ScriptInclude was not used?&lt;/P&gt;
&lt;P&gt;As you pointed out, even if I tried to decrypt with a short text, it returned the text as it was encrypted&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 10:12:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408533#M65459</guid>
      <dc:creator>Koki</dc:creator>
      <dc:date>2022-04-01T10:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Decryption using "Glide Encrypter</title>
      <link>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408534#M65460</link>
      <description>&lt;P&gt;Yes. Should use Script Include to decrypt text from scoped application.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 06:58:22 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/decryption-using-quot-glide-encrypter/m-p/1408534#M65460</guid>
      <dc:creator>Hitoshi Ozawa</dc:creator>
      <dc:date>2022-04-02T06:58:22Z</dc:date>
    </item>
  </channel>
</rss>

