[Java] Private Key Signing - Public Key Verifying
Private key 서명과 이를 public key로 인증하는 Java 예제
1. data 생성
2. private key signing
3. public key verify
1. data 생성
2. private key signing
3. public key verify
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2048); KeyPair keyPair = keyGen.generateKeyPair(); PublicKey publicKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate(); // create a data byte[] data = new byte[10000]; ThreadLocalRandom.current().nextBytes(data); // sign using the private key Signature sig = Signature.getInstance("SHA256withRSA"); sig.initSign(privateKey); sig.update(data); byte[] signature = sig.sign(); // verify signature using the public key sig.initVerify(publicKey); sig.update(data); boolean keyPairMatches = sig.verify(signature);
댓글
댓글 쓰기