While doing integration with some soap/rest receiver through SAP PI/PO, they may ask to do RSA signature and Base64 encoding for some of the fields.
The soap/rest receiver should provide the private key to the sender. When they receive any message with RSA signature by a private key, they will use their own public key to verify the private key to check if the data is sent from a legal sender.
For this kind of requirements, we can do in SAP PI/PO by using Java mapping or UDF.
In this post, I will explain how to use UDF to do RSA signature and Base64.
Before the mapping, the soap/rest receiver should provide the private key to SAP PO.
We are starting at the message mapping as below. (DT MT and SI creation steps are skipped)
Create the UDF privateKeyEncrypt as below.
Figure 2:UDF
The code attached:
public String privateKeyEncrypt(String str, String privateKey, Container container) throws StreamTransformationException{
try {
//base64
byte[] decoded = Base64.getDecoder().decode(privateKey);
PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded));
//RSA
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, priKey);
String outStr = Base64.getEncoder().encodeToString(cipher.doFinal(str.getBytes()));
return outStr;
} catch (Exception e) {
throw new StreamTransformationException(e.getMessage());
}
}
Use the UDF for the segment sign. The 2nd input Constant should be the private key provided by the receiver.
Figure 3: field mapping
Test:
The string abc will be encrypted and base64 to a different string as below.
Figure 4: test result
Please share your feedback or thoughts in a comment
And you can follow the SAP Process Orchestration environment Topic page (https://community.sap.com/topics/process-orchestration),
Post and answer questions about SAP Process Orchestration (https://answers.sap.com/tags/477916618626075516391832082074785),
and read other posts on the topic (https://blogs.sap.com/tags/477916618626075516391832082074785/)
For similar content, please follow my profile(Tom Young) and I will try to post more in the future.