KlaraKlartext

for script lover / hater ^^

Feb 9th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. for script lover and hater ^^
  2.  
  3. (defn encrypt [bytes public-key]
  4. (let [cipher (doto (javax.crypto.Cipher/getInstance "RSA/ECB/PKCS1Padding" "BC")
  5. (.init javax.crypto.Cipher/ENCRYPT_MODE public-key))]
  6. (.doFinal cipher bytes)))
  7.  
  8.  
  9. (defn decrypt [bytes private-key]
  10. (let [cipher (doto (javax.crypto.Cipher/getInstance "RSA/ECB/PKCS1Padding" "BC")
  11. (.init javax.crypto.Cipher/DECRYPT_MODE private-key))]
  12. (.doFinal cipher bytes)))
  13. Signing,
  14.  
  15. (defn sign [data private-key]
  16. (let [sig (doto (java.security.Signature/getInstance "SHA1withRSA" "BC")
  17. (.initSign private-key (java.security.SecureRandom.))
  18. (.update data))]
  19. (.sign sig)))
  20.  
  21. (defn verify [signuture data public-key]
  22. (let [sig (doto (java.security.Signature/getInstance "SHA1withRSA" "BC")
  23. (.initVerify public-key)
  24. (.update data))]
  25. (.verify sig signuture)))
  26. Usage,
  27.  
  28. (comment
  29. (defn read-to-byte [f]
  30. (let [file (java.io.RandomAccessFile. f "r")
  31. content (make-array Byte/TYPE (.length file))]
  32. (.read file content)
  33. content))
  34.  
  35. go here get all
  36. http://nakkaya.com/2012/10/28/public-key-cryptography/
  37. et Another Disposable E-Mail Web Application in Clojure
  38. http://nakkaya.com/2012/07/25/yet-another-disposable-e-mail-web-application-in-clojure/
  39.  
  40.  
  41.  
  42. http://nakkaya.com/2012/10/28/public-key-cryptography/
  43. http://nakkaya.com/2012/08/13/google-hotp-totp-two-factor-authentication-for-clojure/
  44. http://nakkaya.com/2009/05/02/ip-over-dns/
Advertisement
Add Comment
Please, Sign In to add comment