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

in.s8.rsa.impl.EncryptImpl Maven / Gradle / Ivy

The newest version!
package in.s8.rsa.impl;

import in.s8.rsa.constant.S8Constant;
import in.s8.rsa.implService.EncryptService;
import org.springframework.stereotype.Component;

import javax.crypto.Cipher;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.ObjectInputStream;
import java.security.interfaces.RSAPublicKey;

/**
 * Created by Sourabh_Sethi on 5/17/2016.
 */
@Component("encryptImpl")
public class EncryptImpl implements EncryptService {

    public byte[] encryptionByteStream(String plainText, RSAPublicKey rsaPK) throws FileNotFoundException {
        byte[] cipherText = null;
        ObjectInputStream inputStream = null;

        try {

            // get an RSA cipher object and print the provider
            final Cipher cipher = Cipher.getInstance(S8Constant.ALGORITHM);

            // rsa the plain text using the public key
            cipher.init(Cipher.ENCRYPT_MODE, rsaPK);

            cipherText = cipher.doFinal(plainText.getBytes());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return cipherText;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy