cancel
Showing results for 
Search instead for 
Did you mean: 

Signing the message in CPI using Private Key

0 Kudos

Hi Experts,

i have a requirement to encrypt a message using the private key and then encode it to base 64. I am able to use the function for encoding but not for encryption. can you please help?

I have used the Simple Signer function but it is not giving any output. .The input and output are same.

i have also tried the below Groovy code but it is giving an error

Error -

java.lang.NoSuchMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.encryptRSAData() is applicable for argument types: (java.lang.String, iaik.security.rsa.RSAPrivateKey)

Code

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.keystore.KeystoreService;
import java.security.cert.Certificate;
import java.security.KeyPair;
import java.security.PrivateKey;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;
import org.apache.commons.codec.binary.Base64;
import groovy.xml.Namespace;
import groovy.util.XmlParser;
import groovy.xml.XmlUtil;

def Message processData(Message message) {
    KeystoreService service = ITApiFactory.getApi(KeystoreService.class, null);
    Certificate cert = service.getCertificate("alias");
    KeyPair keypair = service.getKeyPair("alias");
    PrivateKey privateKey = keypair.getPrivate();

    //Body 
    def body = message.getBody(java.lang.String) as String;
    String encryptedXMLData = encryptRSAData(body, privateKey);
    return encryptedXMLData;
}

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

achieved this. The Signer function works but the catch is that the output goes to the header. Access the header to get the signed value.

0 Kudos

Hello Wipro Basis Team,

I have a similar requirement, could you please share the code for the same.

Regards

Ashish

Answers (1)

Answers (1)

former_member378845
Discoverer
0 Kudos

Hi team,

I have come up with same requirement , could you please guide us the process to sign a message with private keys and then to convert to base 64 in SAP ABAP.

Thanks.