How to store byte into bytearray
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 05:37 AM
Hi All,
I am trying to retrieve a certificate from third party and in response I am getting certificate bytes. How do I store certificate byte in an array and then finally write to file?
Request
POST https://abc.example/abcd/certificates/Retrieve
X-Api-Key: 7cd2319e-5b50-4fe1-a3b6-d40c5fe1d156
{
"CertificateDN": "\\VED\\Policy\\www.abc.com",
"Format": "Base64"
}
Response
HTTP/1.1 200 OK
{
"CertificateData":"LS0tLS1CRUdLS0tLS0NCg==",
"Filename":"www.venafi.com.cer",
"Format":"Base64"
}
I wanted to convert my certificate data in below format. Please suggest.
"-----BEGIN CERTIFICATE REQUEST-----
MIIDGzCCAgMCAQAwXTEXMBUGCgmSJomT8ixkARkWB2V4YW1wbGU/ WPlT2R3xw
98+dnGb7yvMaIxDWB5pdlb43pQxdxS0tZgVcClE6fDKCg5+bdffacA==
-----END CERTIFICATE REQUEST-----"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 06:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 07:02 AM
Hi dj2,
Yes I am saving the response in a custom table. The end goal is to allow user to download this certificate on his/her machine.
Can you please suggest a approach.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 07:18 AM
You could use the code snippet i shared. you can pass the response data(base64) form the third party as ecc "payload".
ecc.source should be a record(sys_id) from your custom table.
ecc.name - this is the name of the certificate file which will be added to the source records as an attachment (please specify the file extension ex. filename.xls)- to uniquely identify you may use the source table record identifier
(When certification file types are opened/ saved from from, Im not very sure how Service now handles the file types- please try and let me know)