You need to sign in to do that
Don't have an account?
.PFX file from Static Resource or Document to Apex
Hello friends long time no see,
Is there a way to upload your .pfx file (private key and certificate) for WebService legacy integration, to Static Resource or Documents to later query it from Apex and then convert it into Base64 string?
Or the only way is to download Openssl and then execute "openssl base64 -in certifIF.pfx -out outputfile.txt" , then open it and copy the whole String?
Cheers
Is there a way to upload your .pfx file (private key and certificate) for WebService legacy integration, to Static Resource or Documents to later query it from Apex and then convert it into Base64 string?
Or the only way is to download Openssl and then execute "openssl base64 -in certifIF.pfx -out outputfile.txt" , then open it and copy the whole String?
Cheers
public static String getResourceBody(String resourceName) {
//Fetching the resource
List<StaticResource> resourceList = [SELECT Id, Body
FROM StaticResource
WHERE Name = :resourceName];
//Checking if the result is returned or not
if(resourceList.size() == 1) {
return EncodingUtil.base64Encode(resourceList[0].Body);
} else {
return '';
}
}
All Answers
public static String getResourceBody(String resourceName) {
//Fetching the resource
List<StaticResource> resourceList = [SELECT Id, Body
FROM StaticResource
WHERE Name = :resourceName];
//Checking if the result is returned or not
if(resourceList.size() == 1) {
return EncodingUtil.base64Encode(resourceList[0].Body);
} else {
return '';
}
}
I have a .PFX SSL certificate file with password. how to import/upload to salesforce and use the same to connect third party applicatoin.
This is very urgent!! Can you pleae help me on this.
Thanks,
Krishna
- Object: yourObject
- Field: 32768 length or more.
- Visualforce should contain:
<apex:pageBlockSectionItem >
<apex:outputLabel value="File .PFX"/>
<apex:inputFile value="{!cerPFX.body}" filename="{!cerPFX.name}" id="idCerPFX" />
</apex:pageBlockSectionItem>
- Class should contain:
// I used attachment since it has a body (blob) field
public Attachment cerPFX {
get {
if (cerPFX == null)
cerPFX = new Attachment();
return cerPFX;
}
set;
}
...
...
...
// Use this if you want to encode & encrypt your string
if (cerPFX.Body != null) {
Blob data = Blob.valueOf(EncodingUtil.base64Encode(cerPFX.Body));
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);
yourObject.File_PFX__c = EncodingUtil.base64Encode(encryptedData);
}
// Insert update your object where the field is
insert/update yourObject;
- To use it inside a webservice, you should query that field with a static string metod.
Thank you very much for Quick reply..
I guess not given proper inputs to you. please see the scenario.
I have created a API and sending some information to third party application using POST. but when i authenticate the Endpoint URL i am getting certificate unauthorized error.
while uploading the certificate into certification management getting the file is corrupted error.
I have uploaded the file into static resources and encrypted the certificate as you mentioned above.
how to add this encrypt value to post method to skip the above error. Is it possible ? because using SOAPUI Tool we are not getting any certification error and it is working fine. Please help me on this.
Thanks,
Krish