
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.
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)
Figure 1:message mapping
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:
Figure 4: test result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
7 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 | |
4 | |
4 |