public class RSATemp

{

private BigInteger p;

private BigInteger q;

private BigInteger N;

private BigInteger phi;

private BigInteger e;

private BigInteger d;

private int bitlength = 2048;

private Random     r;






public RSATemp(BigInteger e, BigInteger d, BigInteger N)

{

    this.e = e;

    this.d = d;

    this.N = N;

}



@SuppressWarnings("deprecation")

public static void main(String[] args) throws IOException
{

    BigInteger modulus = new BigInteger("732304722617848367419348177225220839621829592747555436845852575397572412766877051456121969465868706640892729788911095462125931999297100561246040644291118994418455830276174251033609308467846074489468059411713692372522558005239890056665102083166938497963291707732178946584433028697249299483419092020446820002067999210191560182570244973034816126251891063310951575129847357058963181008692621498656560990566368827473497974506879945123113726917826410595887194849510508345963100044941944468704636036393849476463496663763135268744181787086597232146046701987312765640971360113074678724789805078566351377286974134255427380172350212840100075631137120026860479503812256563383188356620222127773175187649849472706588526367662043327788488031316103998835805617430875725758300709180754198396030226810976581107381492952338322931954830521282278113296010170504217010974263975930049281876449397269488989478264653638037650168277495702805751027509778162370762025620389050550046300367029356031671742902373679912628514996806431272860328089056934948254306319251896601067378768040964123261013184262895817105724217015934297041244101106936616308041773995356148497292385435616023280744848436708432952882324956849251856204325701223262511347562477060385973770138849");

    BigInteger publicExp = new BigInteger("144397757996063158447575475910686040513275983853393810738511210923431924128628148462946345388713638660087060799111356540077670127219811759491673344774753238105188002151237540703290724057483079838859058258039354083803134967848859998471795897115359442049715321583795358053951221179180300120100127949736220075069");

    BigInteger privateExp = new BigInteger("473277612250116772783840425409815427048737772406453069608478575386208125616952441418911073623505892312981180817947458643971020616861724366604448911653674546779265107718651161826558156103967509728949727120967852942904535607392879725599115315075930491905031748204272137295614541602636580984726947181649021622908162060515930076854343315675532386432185871358258303128018698706542551408882279743263868586059453780702883038917486555968430415779977505479221501494093099414345720711478104623028681099594361633285208210495501843383121120869183311310124497689623203963143700365409004276285706422795468448458928587795341478278057355685962942224234686451827213643853667966335708584639473335276400177406659823155945143268277844360972301081184790218559903670365765754750799562207576159461904860493740705084117687292693450684982107422959320544577255592826808354579299156678400646251074217032985604039293684790105579931669501143144705992492566778155012154958818751449853735084389580273783227114753150929832005101589501297365523976230557211740948005188710663700109505603319562343088254173608336389543135453007553195932035008790912455145376017517899258170400204720850887286757724056690243981097750575188312748643773157901931111813208723907908454339629");

   // RSATemp rsa = new RSATemp();

    RSATemp rsa = new RSATemp(publicExp, privateExp, modulus);

           String teststring="sunil yadav";

    System.out.println("Encrypting String: " + teststring);

    System.out.println("String in Bytes: "+ bytesToString(teststring.getBytes()));

    // encrypt
    byte[] encrypted = rsa.encrypt(teststring.getBytes());

    // decrypt
    String encryptedString = Base64.encodeBase64URLSafeString(encrypted);
    System.out.println("cipher: " + encryptedString);
    System.out.println(teststring.length());

    byte[] decrypted = rsa.decrypt(encrypted);

    String decryptedString = new String(decrypted);
    System.out.println("plain : " + decryptedString);

    System.out.println("Decrypting Bytes: " + bytesToString(decrypted));

    System.out.println("Decrypted String: " + new String(decrypted));

}

private static String bytesToString(byte[] encrypted)

{

    String test = "";

    for (byte b : encrypted)

    {

        test += Byte.toString(b);

    }

    return test;

}



// Encrypt message

public byte[] encrypt(byte[] message)
{
    return (new BigInteger(message)).modPow(e, N).toByteArray();

}



// Decrypt message

public byte[] decrypt(byte[] message)

{

    return (new BigInteger(message)).modPow(d, N).toByteArray();

}

}