Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for script lover and hater ^^
- (defn encrypt [bytes public-key]
- (let [cipher (doto (javax.crypto.Cipher/getInstance "RSA/ECB/PKCS1Padding" "BC")
- (.init javax.crypto.Cipher/ENCRYPT_MODE public-key))]
- (.doFinal cipher bytes)))
- (defn decrypt [bytes private-key]
- (let [cipher (doto (javax.crypto.Cipher/getInstance "RSA/ECB/PKCS1Padding" "BC")
- (.init javax.crypto.Cipher/DECRYPT_MODE private-key))]
- (.doFinal cipher bytes)))
- Signing,
- (defn sign [data private-key]
- (let [sig (doto (java.security.Signature/getInstance "SHA1withRSA" "BC")
- (.initSign private-key (java.security.SecureRandom.))
- (.update data))]
- (.sign sig)))
- (defn verify [signuture data public-key]
- (let [sig (doto (java.security.Signature/getInstance "SHA1withRSA" "BC")
- (.initVerify public-key)
- (.update data))]
- (.verify sig signuture)))
- Usage,
- (comment
- (defn read-to-byte [f]
- (let [file (java.io.RandomAccessFile. f "r")
- content (make-array Byte/TYPE (.length file))]
- (.read file content)
- content))
- go here get all
- http://nakkaya.com/2012/10/28/public-key-cryptography/
- et Another Disposable E-Mail Web Application in Clojure
- http://nakkaya.com/2012/07/25/yet-another-disposable-e-mail-web-application-in-clojure/
- http://nakkaya.com/2012/10/28/public-key-cryptography/
- http://nakkaya.com/2012/08/13/google-hotp-totp-two-factor-authentication-for-clojure/
- http://nakkaya.com/2009/05/02/ip-over-dns/
Advertisement
Add Comment
Please, Sign In to add comment