Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hasherv2;
  7.  
  8. import java.security.InvalidKeyException;
  9. import java.security.KeyPair;
  10. import java.security.KeyPairGenerator;
  11. import java.security.NoSuchAlgorithmException;
  12. import java.security.PrivateKey;
  13. import java.security.PublicKey;
  14. import java.security.Signature;
  15. import java.security.SignatureException;
  16.  
  17. /**
  18. *
  19. * @author Taury55
  20. */
  21. public class HasherV2 {
  22.  
  23. /**
  24. * @param args the command line arguments
  25. */
  26. public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
  27. KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
  28. keyPairGenerator.initialize(512);
  29. KeyPair keyPair = keyPairGenerator.generateKeyPair();
  30.  
  31. PublicKey publicKey = keyPair.getPublic();
  32. PrivateKey privateKey = keyPair.getPrivate();
  33.  
  34. Signature signGenerator = Signature.getInstance("SHA1withRSA");
  35. signGenerator.initSign(privateKey);
  36.  
  37. String msg = "Hello World";
  38.  
  39. signGenerator.update(msg.getBytes());
  40.  
  41. byte[] podpis = signGenerator.sign();
  42.  
  43. byte[] key = publicKey.getEncoded();
  44.  
  45. System.out.println(msg);
  46. for (byte c : podpis) {
  47. System.out.format("%02x", c);
  48. }
  49. System.out.println();
  50. for (byte a : key) {
  51. System.out.format("%02x", a);
  52. }
  53. System.out.println();
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement