try {
// Encrypt the premaster secret
BigInteger input = new BigInteger(1, premasterSecret);
PublicKey key = x509.getPublicKey();
if (key instanceof RsaPublicKey) {
BigInteger padded = Rsa.padPKCS1(input, 0x02, 128);
BigInteger s = Rsa.doPublic(padded, ((RsaPublicKey) key).getModulus(), ((RsaPublicKey) key).getPublicExponent());