Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP to encrypt password with a RSA public-key string

0 Kudos

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 https://archive.sap.com/discussions/thread/3587670.

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" +
            "OQE5VFOIXPVTaa25mQIDAQAB";
    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" );
    }

1 REPLY 1

sourav2117
Participant

Hi Did you solve this issue as i am also getting this kind of issue .