This code was werking perfect a few versions ago but now i cannot use the result of the sign anymore to get my signed documents with the latest versions so i cannot upgrade.
What is wrong?
function TSignedURLCalculator.Sign(aStringToSign: string): string;
const
cPrefix = '-----BEGINRSAPRIVATEKEY-----';
cSuffix = '-----ENDRSAPRIVATEKEY-----';
var
sSignedURL: string;
RSAUtil: TRSAEncSign;
begin
Result := '';
RSAUtil := TRSAEncSign.Create;
RSAUtil.keyLength := TRSAKeyLength.kl2048;
RSAUtil.OutputFormat := hexa;
RSAUtil.Unicode := yesUni;
RSAUtil.encType := oaep;
RSAUtil.withOpenSSL := True;
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey,' ','',[rfReplaceAll, rfIgnoreCase]);
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey,'''','',[rfReplaceAll, rfIgnoreCase]);
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey,#13,'',[rfReplaceAll, rfIgnoreCase]);
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey,#10,'',[rfReplaceAll, rfIgnoreCase]);
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey, cPrefix,'',[rfReplaceAll, rfIgnoreCase]);
URLC.FPrivateKey := StringReplace(URLC.FPrivateKey, cSuffix,'',[rfReplaceAll, rfIgnoreCase]);
if URLC.FPrivateKey = '' then
Raise Exception.CreateFmt('No valid private key present: "%s"',[URLC.FPrivateKey]);
try
// Must be an RSA Private Key in PEM format (not another type of private key)
RSAUtil.FromOpenSSLPrivateKeyString(URLC.FPrivateKey);
RSAUtil.signType := TRSASignType(1);
sSignedURL := RSAUtil.Sign(aStringToSign);
Result := sSignedURL;
finally
RSAUtil.Free;
end;
end;