Code example for RSAPublicKey

Methods: getModulus

0
		KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
		KeyPair kp = kpg.generateKeyPair();
		RSAPrivateKey privateRSA = (RSAPrivateKey) kp.getPrivate();
		RSAPublicKey publicRSA = (RSAPublicKey) kp.getPublic();
 
		byte[] pub = publicRSA.getModulus().toByteArray();
		System.arraycopy(pub, 1, RSAPublicKey, 0, 128);
 
		RSAEncrypt.init(Cipher.ENCRYPT_MODE, publicRSA);
		RSADecrypt.init(Cipher.DECRYPT_MODE, privateRSA);
 
		/* 
		try 
		{ 
			//byte[] enc = encryptRSA("asd".getBytes()); 
			//Utils.printPacket(enc); 
			//byte[] dec = decryptRSA(enc); 
			//System.out.println(new String(dec)); 
		} 
		catch(BadPaddingException e) 
		{