Skip to content

Instantly share code, notes, and snippets.

View SOAPClientSample.java
/ *
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
import java.util.Base64;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@RevenueGitHubAdmin
RevenueGitHubAdmin / encode_password.js
Created June 14, 2018 16:13
[JavaScript] How to encode the password to open the keystore.
View encode_password.js
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to generate the MD5 hash of a plain text String and encode the result into a BASE64 String. This
* snippet exemplify how to proper encode the keystore password before use it to access the certificate
* and keys. For more information about how to use the Forge JavaScript library, please, refer to
* the aforementioned URL.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
@RevenueGitHubAdmin
RevenueGitHubAdmin / open_keystore.js
Created June 14, 2018 16:12
[JavaScript] How to open the KeyStore.
View open_keystore.js
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to open the keystore file containing the certificate and key pairs used to sign the requests to be
* sent. The first parameter expected is the absolute path for the keystore to be used. The second
* parameter expected is the MD5 hash of keystore's password, encoded using BASE64. For more information
* about how to use the Forge JavaScript library, please, refer to the aforementioned URL.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
@RevenueGitHubAdmin
RevenueGitHubAdmin / load_certificate.js
Created June 14, 2018 16:12
[JavaScript] How to retrieve the certificate and the private key from the KeyStore.
View load_certificate.js
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to retrieve the certificate and the private key from the keystore. It receives a Forge's PKCS12
* object instance and returns a simple object containing the retrieved certificate and private key
* (assuming that the keystore contains only one certificate). The certificate is required to be sent
* with the signed request, while the private key is used to sign the request before send it.
* For more information about how to use the Forge JavaScript library, please, refer to the aforementioned URL.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
@RevenueGitHubAdmin
RevenueGitHubAdmin / encode_certificate.js
Created June 14, 2018 16:11
[JavaScript] How to encode the certificate.
View encode_certificate.js
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to encode the binary representation of the certificate into a BASE64 String to be sent
* together with the signed request. For more information about how to use the Forge JavaScript
* library, please, refer to the aforementioned URL.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
@RevenueGitHubAdmin
RevenueGitHubAdmin / calculate_element_digest.js
Created June 14, 2018 16:11
[JavaScript] How to calculate and encode an element digest.
View calculate_element_digest.js
/*
* The following snippet uses the Forge JavaScript library (https://github.com/digitalbazaar/forge)
* to calculate the SHA512 digest hash of the received element and return it as a BASE64
* encode String. It is used to calculate the digest of the content of the request and it
* is an important element of the signature. The expected parameter is the plain text
* representation of the request's body being sent. For SOAP, it is the XML node being signed.
* For RESTful is the JSON document beingin sent. For more information about how to use the
* Forge JavaScript library, please, refer to the aforementioned URL.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
@RevenueGitHubAdmin
RevenueGitHubAdmin / EncodePassword.java
Created June 14, 2018 16:09
[Java] How to encode the password to open the keystore.
View EncodePassword.java
/*
* The following snippet generates the MD5 hash of a plain text String and encode the result
* into a BASE64 String. This snippet exemplify how to proper encode the keystore password
* before use it to access the certificate and keys.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
public String encodePassword(String plainTextPassword) throws NoSuchAlgorithmException {
@RevenueGitHubAdmin
RevenueGitHubAdmin / CalculateElementDigest.java
Last active November 5, 2018 09:46
[Java] How to calculate and encode an element digest.
View CalculateElementDigest.java
/*
* The following snippet calculates the SHA512 digest hash of the received element and return it as a BASE64
* encode String. It is used to calculate the digest of the content of the request and it is an important
* element of the signature. The expected parameter is the plain text representation of the request's body
* being sent. For SOAP, it is the XML node being signed. For RESTful is the JSON document being sent.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
@RevenueGitHubAdmin
RevenueGitHubAdmin / OpenKeyStore.java
Created June 14, 2018 16:07
[Java] How to open the KeyStore.
View OpenKeyStore.java
/*
* The following snippet opens an external keystore file and returns it to be used to retrieve
* certificates and keys. This is an important step, once that the certificate and the private
* key contained in the keystore will be used to sign the requests.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
public KeyStore openKeyStore(String filePath, String encodedPassword) throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException {
@RevenueGitHubAdmin
RevenueGitHubAdmin / GetCertificateAndKeyFromKeyStore.java
Created June 14, 2018 16:07
[Java] How to retrieve the certificate and the private key from the KeyStore.
View GetCertificateAndKeyFromKeyStore.java
/*
* The following snippet retrieves, from an already loaded keystore, the certificate and the
* private key used to sign the requests. It takes as assumption that the keystore contains
* only one certificate.
*
* Gists provided for illustrative purposes only. Developers can use these as a support tool
* but the Office of the Revenue Commissioners (Revenue) does not provide any warranty with
* these gists.
*/
public void getCertificateAndKeyFromKeyStore(KeyStore keyStore, String encodedPassword) throws KeyStoreException, UnrecoverableEntryException, NoSuchAlgorithmException {