i am making a request to a endpoint in apex. i have encrypted data and key using crypto class, now i want to send the encrypted data and token id in the request header for authorization using GET method. the below code is not working and no data is getting pulled from the endpoint api.
(note: api using basic authorization is working fine.)
below is my code.
public static string encryptMessage(String message, String secretKey){
Blob key = EncodingUtil.base64Decode(secretKey);
Blob data = Blob.valueOf(message);
Blob encrypted = Crypto.encryptWithManagedIV('AES128', key, data);
return EncodingUtil.base64Encode(encrypted);
}
String secretKey = 'xxxxxxxxxxxxxxxxxxxxxx==';
String tokenId = 'xxxxxxxxxxxx';
Datetime d = System.now();
String payload = 'd='+d.format('yyyyMMddHHmmssSSSZ')+';c='+10+';t='+10;
String message = tokenId + ':' + encryptMessage(payload, secretKey);
HttpRequest req = new HttpRequest();
req.setEndpoint('my endpoint url');
req.setHeader('Accept', 'application/xml;charset=UTF-8');
req.setHeader('Authorization', 'OAuth' + EncodingUtil.base64Encode(blob.valueOf( message)));
Http http = new Http();
HTTPResponse res = http.send(req);
string response = res.getBody();