Skip to Content

ABAP to encrypt password with a RSA public-key string

Hi guys

Is there any possible to implement the following java code in ABAP?

As you can see, I have a public-key string and users will input their password.

Now I need to get the encrypted password with PKCS#1 protocol.

I have read a lot of articles like

However I have no idea how to use SSF_KRN_ENVELOPE function.

public class Main {
    static final String pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7JL0DcaMUHumSdhxXTxqiABBC\n" +
            "DERhRJIsAPB++zx1INgSEKPGbexDt1ojcNAc0fI+G/yTuQcgH1EW8posgUni0mcT\n" +
            "E6CnjkVbv8ILgCuhy+4eu+2lApDwQPD9Tr6J8k21Ruu2sWV5Z1VRuQFqGm/c5vaT\n" +
    public String userid;
    public String tokenid;

    private static String RSAEncode(String pass) throws IOException, GeneralSecurityException {
        KeyFactory kf = KeyFactory.getInstance( "RSA" );
        PublicKey publicKey = kf.generatePublic( new X509EncodedKeySpec( new BASE64Decoder().decodeBuffer( pubKey ) ) );

        Cipher cipher = Cipher.getInstance( "RSA/ECB/PKCS1Padding" );
        cipher.init( Cipher.ENCRYPT_MODE, publicKey );
        return new BASE64Encoder().encode( cipher.doFinal( pass.getBytes( "UTF-8" ) ) ).replace( "\r\n", "\n" );

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers