{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":977,"path":"api-reference/server-api-reference/c_CertificateEncryptionScopedAPI.md","title":"CertificateEncryption - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# CertificateEncryption- Scoped\n\nThe CertificateEncryption API provides methods for encrypting certificates in scoped applications.\n\nUse these methods to generate a hash for the certificate, sign data using a private key, and generate a message authentication code.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## CertificateEncryption - CertificateEncryption\\(\\)\n\nInstantiates a CertificateEncryption object in a scoped application.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n## CertificateEncryption - generateMac\\(String key, String algorithm, String data\\)\n\nGenerates the Message Authentication Code \\(MAC\\), which is used to authenticate a message.\n\n|Name|Type|Description|\n|----|----|-----------|\n|key|String|Key to use to sign the message. Must be Base64 encoded.|\n|algorithm|String|Algorithm to use to generate the MAC: HmacSHA256, HmacSHA1, HmacMD5, and so on.|\n|data|String|Data to process.|\n\n|Type|Description|\n|----|-----------|\n|String|MAC in base64 format.|\n\nThis example shows how to a MAC using sample\\_key as the data and HmacSHA256 as the algorithm.\n\n```\nvar mac = new CertificateEncryption;\nvar key = \"sample_key\"; \nkey = gs.base64Encode(key);\nmac.generateMac(key, \"HmacSHA256\", \"sample_data\");\n```\n\n## CertificateEncryption - getThumbPrint\\(String certificateID, String algorithm\\)\n\nGenerates a hash \\(SHA-1, SHA-256, and so on\\) for the certificate from Trust Store Cert.\n\n|Name|Type|Description|\n|----|----|-----------|\n|certificateID|String|Sys\\_id of the certificate record in the X.509 Certificate \\[sys\\_certificate\\] table.|\n|algorithm|String|Algorithm to use to create the hash, such as SHA-1, SHA-256, and so on.|\n\n|Type|Description|\n|----|-----------|\n|String|Thumbprint in base64 format.|\n\nThis example shows how to generate the thumbprint \\(hash\\) for the AzureAAD certificate.\n\n```\n//Create a GlideRecord to the certificate table\nvar x509GR = new GlideRecord('sys_certificate');\n\n//If there is a certificate of a name of AzureAAD, get the certificate thumbprint\nif(x509GR.get('name', 'AzureAAD')){\n\n//Use the sys_id and algorithm we want to create a thumbprint\nvar thumbPrint = CertificateEncryption.getThumbPrint(x509GR.getUniqueValue(), \"SHA-1\");\n\n//Print the created thumbprint\ngs.print(\"Thumbprint for \" + x509GR.getDisplayValue() + \" is \" + thumbPrint);\n}\n```\n\nOutput:\n\n```\nV1X+aguDBTZVVbWMGTXxdzJLmaY=\n```\n\n## CertificateEncryption - getThumbPrintFromKeyStore\\(String certificateID, String alias, String algorithm\\)\n\nGenerates a hash \\(SHA-1, SHA-256, and so on\\) for the certificate from the keystore entry.\n\n|Name|Type|Description|\n|----|----|-----------|\n|certificateID|String|Sys\\_id of the certificate record in the X.509 Certificate \\[sys\\_certificate\\] table.|\n|alias|String|Alias name for the certificate.|\n|algorithm|String|Algorithm to use to create the hash, such as SHA-1, SHA-256, and so on.|\n\n|Type|Description|\n|----|-----------|\n|String|Thumbprint in base64 format.|\n\n## CertificateEncryption - sign\\(String certificateID, String alias, String aliaspassword, String algorithm, String datatosign\\)\n\nSigns the data using the private key and the specified algorithm.\n\n<table id=\"table_edb_rmv_js\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncertificateID\n\n</td><td>\n\nString\n\n</td><td>\n\nsys\\_id of the certificate record in the X.509 Certificate \\[sys\\_certificate\\] table.\n\n</td></tr><tr><td>\n\nalias\n\n</td><td>\n\nString\n\n</td><td>\n\nPrivate key name.\n\n</td></tr><tr><td>\n\naliaspassword\n\n</td><td>\n\nString\n\n</td><td>\n\nPassword for the private key.\n\n</td></tr><tr><td>\n\nalgorithm\n\n</td><td>\n\nString\n\n</td><td>\n\nAlgorithm to use. Must be one of the following values:-   NONEwithRSA\n-   MD2withRSA\n-   MD5withRSA\n-   SHA1withRSA\n-   SHA224withRSA\n-   SHA256withRSA\n-   SHA384withRSA\n-   SHA512withRSA\n-   NONEwithDSA\n-   SHA1withDSA\n-   SHA224withDSA\n-   SHA256withDSA\n-   NONEwithECDSA\n-   SHA1withECDSA\n-   SHA224withECDSA\n-   SHA256withECDSA\n-   SHA384withECDSA\n-   SHA512withECDSA\n\n</td></tr><tr><td>\n\ndatatosign\n\n</td><td>\n\nString\n\n</td><td>\n\nData to sign.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Signed data in base64 format.|\n\n```\nvar ce = new CertificateEncryption;\nce.sign(\"recordID\", \"alias\", \"password\", \"SHA1withRSA\", \"sign this data\");\n```\n\n"}}