Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hasherv2;
- import java.security.InvalidKeyException;
- import java.security.KeyPair;
- import java.security.KeyPairGenerator;
- import java.security.NoSuchAlgorithmException;
- import java.security.PrivateKey;
- import java.security.PublicKey;
- import java.security.Signature;
- import java.security.SignatureException;
- /**
- *
- * @author Taury55
- */
- public class HasherV2 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
- KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
- keyPairGenerator.initialize(512);
- KeyPair keyPair = keyPairGenerator.generateKeyPair();
- PublicKey publicKey = keyPair.getPublic();
- PrivateKey privateKey = keyPair.getPrivate();
- Signature signGenerator = Signature.getInstance("SHA1withRSA");
- signGenerator.initSign(privateKey);
- String msg = "Hello World";
- signGenerator.update(msg.getBytes());
- byte[] podpis = signGenerator.sign();
- byte[] key = publicKey.getEncoded();
- System.out.println(msg);
- for (byte c : podpis) {
- System.out.format("%02x", c);
- }
- System.out.println();
- for (byte a : key) {
- System.out.format("%02x", a);
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement