I tried and learn the cryptography tools present in Bigloo. I followed the
steps from the manual carefully. As Maxwell Smart would put it, I used the
old trick of copying and pasting the instructions from the manual. Here is
what I did:

emacs &

>From emacs:

M-x shell

~/wrk/crypto$ openssl genrsa -out my_rsa_key.pem 1024
Generating RSA private key, 1024 bit long modulus
..++++++
...........................................................++++++
e is 65537 (0x10001)
~/wrk/crypto$ bigloo
------------------------------------------------------------------------------
Bigloo (4.1a)
,--^,
`a practical Scheme compiler'                                      _ ___/
/|/
Thu Feb 20 08:08:12 CET 2014                                   ,;'( )__, )
'
Inria -- Sophia Antipolis                                     ;;  //
L__.
email: [email protected]                              '   \    /
'
url: http://www-sop.inria.fr/indes/fp/Bigloo                       ^
^
------------------------------------------------------------------------------


1:=> (module rsa-example (library crypto))
#unspecified
1:=> (define *key* (read-pem-key "my_rsa_key.pem"))
(define *public-key* (extract-public-rsa-key *key*))

*key*
1:=> *public-key*
1:=> ;; publish the *public-key*:
(write-pem-key-string *public-key*)
-----BEGIN PUBLIC KEY-----
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgK/BcqMKzd3vaYAF0dfHFPB4VdisbsNPzBtPSMhQ
sAWbgeyVcnvSGx3/TYEGQOVTFrl1qZQ+PRh+rtYOQqtxM5q1p/F8JUzZ5sUWUGx2eznZUAtE3jnt
11VMLtpTGPYvpy2tkg65gpXNwuv/XA/6w6dlJkHCV2AXXlWEY8NaqobdAgMBAAE=
-----END PUBLIC KEY-----

1:=> (define msg-hash (sha1sum "my message"))
(define msg-hash-bignum (octet-string->bignum msg-hash))
msg-hash
1:=> msg-hash-bignum
1:=> (define msg-hash-bignum (octet-string->bignum (string-hex-intern
msg-hash)))
msg-hash-bignum
1:=> (define signature (rsa-sign *key* msg-hash-bignum))
signature
1:=> (rsa-verify *public-key* msg-hash-bignum signature)
#t
1:=> (define encrypted (encrypt 'aes "Cryptography" "my random password"))
encrypted
1:=> (define encrypted-key (rsa-encrypt *public-key* (octet-string->bignum
"my random password")))
encrypted-key
1:=> (define aes-key (bignum->octet-string (rsa-decrypt *key*
encrypted-key)))
aes-key
1:=> (decrypt 'aes aes-key encrypted)
^\\274
1:=>

As you can see from the listing, I did not get the string "Cryptography"
back. Instead of it, I got ^\\274. The fun would be even greater if I had
gotten ^\\42.

Reply via email to