I have exported a class 3 Digital certificate and I am able to get the details from the object named cert as seen below. I intend to sign a text file using this certificate. However since I exported this certificate without the private key, I am unable to proceed. I have shared a snippet below the image which has tags.
This is the file saved as .txt and the tags and will be the result of the signing process. So basically the raw payload will only have the other tags before the signing process.
My Questions:
Am I on the right track to digitally sign the text file from backend?
Should the access of the certificate be handled on the client side using Javascript
try (InputStream inStream = new FileInputStream("D:\\New folder\\TestCertificate.cer")) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream);
cert.checkValidity();
System.out.println("This is public key : " + cert.getPublicKey());
System.out.println("This is certificate type: " + cert.getType());
// Code to access a txt file and sign it with the certificate.
} catch (CertificateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
<MessageInfo>
<SenderIden>XSB000000000</SenderIden>
<SenderSP>100023193</SenderSP>
<Data><![CDATA[{IFN515}{XSB000000000}{XYZ12345}
{
:16R:GENL
:20C::SEME//A23P8W4
:23G:NEWM
:98A::PREP//20220221
:22F::TRTR//TRAD
]]></Data>
<SubscriberDS>MIIJuwYJKoZIhvcNAQcCoI</SubscriberDS>
<ServiceProviderDS>MIIJuwYJKoZI</ServiceProviderDS>
</MessageInfo>