All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.worldpay.cse.jwe.WPRSAEncrypter Maven / Gradle / Ivy

Go to download

Android SDK is a library created to help you integrate Worldpay client side encryption into your mobile applications.

There is a newer version: 1.0.4
Show newest version
package com.worldpay.cse.jwe;

import java.security.Key;

import javax.crypto.Cipher;

import com.worldpay.cse.exception.WPCSEException;

/**
 * The RSA1_5 encrypter used for JWE key encryption. The encrypter is initialized with just the public key or a generic(private & public) RSA key.
 */
class WPRSAEncrypter implements WPEncrypter {

    private static final String RSA_ECB_PKCS1_PADDING = "RSA/ECB/PKCS1Padding";
    
    private Key key;

    /**
     * Creates a RSA1_5 encrypter based on the provided RSA (public) key
     * @param key the RSA key
     */
    public WPRSAEncrypter(Key key) {
        this.key = key;
    }

    @Override
    public byte[] encrypt(byte[] data) {
        try {
            Cipher cipher = Cipher.getInstance(RSA_ECB_PKCS1_PADDING);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            return cipher.doFinal(data);
        } catch (Exception e) {
            throw new WPCSEException(e.getMessage(), e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy