This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ * | |
* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 { |
NewerOlder