Code example for SecureRandom

Methods: nextBytes

0
	} 
 
	public void init() throws Exception { 
		plainBytes = new byte[1024]; // 1k
 
		SecureRandom random = new SecureRandom();
		random.nextBytes(plainBytes);
 
		KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
		keyPairGen.initialize(512);
		KeyPair keyPair = keyPairGen.generateKeyPair();
//		PublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); 
		PrivateKey privateKey = keyPair.getPrivate();
		signature = Signature.getInstance("SHA1withRSA");
 
		signature.initSign(privateKey);
		 
		signature.update(plainBytes);
		signedBytes = signature.sign();
	} 
Experience pair programming with AI  Get Codota for Java