* @throws GeneralSecurityException
* @throws IOException
*/
public RSAEncryptedData encrypt(byte[] data) throws GeneralSecurityException, IOException {
// create a tempoary desEncrypter with random desKEY
DESEncrypter desEncrypter = new DESEncrypter();
desEncrypter.init();
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(RSAKeyPairUtils.getPublicKey(_keyPair));
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Cipher ecipher = Cipher.getInstance("RSA");
ecipher.init(Cipher.ENCRYPT_MODE, keyFactory.generatePublic(pubKeySpec));
// encrypt desKey with rsaPubKey
byte[] desKey = ecipher.doFinal(desEncrypter.getKey().getEncoded());
// encrypt data with des key
String desData = desEncrypter.encrypt(data);
return new RSAEncryptedData(Base64.encode(desKey), desData);
}