2 last update 4/24/02 dmitch
6 This directory contains a program which demonstrates how to
7 write code associated with the RSA Public Key Cryptosystem using
8 the CDSA API. One command-line executable program, called rsatool,
9 currently resides here.
14 See the README in the parent directory (CDSA_Examples) for
15 information on building this program.
20 Rsatool is a UNIX command-line program which operates on files.
21 It can generate key pairs (storing them in files), encrypt a file
22 (placing the result in another file), decrypt, sign a file (placing
23 the signature in another file), and verify signatures.
25 Please note that this type of operation, in which private keys
26 are stored in files which anyone can read, is certainly not
27 recommended security procedure; the purpose of this tool is to
28 demonstrate the use of the CDSA API.
30 To get a full list of rsatool's command-line options, just run it
34 usage: ./rsatool op [options]
44 k=keyfileBase keys are keyFileBase_pub.der, keyFileBase_priv.der)
48 b=keySizeInBits (default 512)
52 a=alg d=DSA r=RSA, e=ECDSA, default = RSA
59 To perform any operations using RSA, one must first have a key pair.
60 You generate them like so:
62 localhost> rsatool g k=mykey b=1024
63 ...wrote 140 bytes to mykey_pub.der
64 ...wrote 636 bytes to mykey_priv.der
67 This generates a 1024-bit key pair, places the public key
68 in mykey_pub.der, and the private key in mykey_priv.der.
70 Now, say you want to encrypt a file. You encrypt with a public key.
71 So first we create a file to encrypt:
73 localhost:> cat > plaintext
74 this is what we will encrypt
77 Now we encrypt it, placing the result in ciphertext:
79 localhost> rsatool e k=mykey p=plaintext c=ciphertext
80 ...wrote 128 bytes to ciphertext
83 The result looks like this:
85 localhost> hexdump ciphertext
86 0000000 8272 4ff9 d7ab 8ff0 3dee 543d 3f36 3d89
87 0000010 ef80 f958 3b4f 1be1 bde8 6557 c215 9728
88 0000020 4262 0c6a b81b 5782 444d 225c db3e 17d7
89 0000030 7079 d3af 7e1e c215 2b14 bf35 20f7 ed33
90 0000040 f311 6258 fd85 6679 e0bb ae33 4b26 c1f8
91 0000050 4f33 ac24 1972 e048 915c 8386 5fc3 7f56
92 0000060 e7b3 9b4a ad6b a192 84c3 fa6e 25ba 91a0
93 0000070 05ef fe42 ebba 0290 99b1 5cc9 5e36 7954
97 We decrypt it like so:
99 localhost> rsatool d k=mykey p=recovered c=ciphertext
100 ...wrote 29 bytes to recovered
105 localhost> cat recovered
106 this is what we will encrypt
109 To generate a digital signature, putting the signature in sigfile:
111 localhost> rsatool s k=mykey p=plaintext s=sigfile
112 ...wrote 128 bytes to sigfile
115 To verify the signature:
117 localhost> rsatool v k=mykey p=plaintext s=sigfile
118 ...signature verifies OK
121 Note what happens if we specify a file other than 'plaintext' to
122 verify with plaintext's signature:
124 localhost> rsatool v k=mykey p=ciphertext s=sigfile
125 CSSM_VerifyData: CSP_VERIFY_FAILED
126 sigVerify: CSP_VERIFY_FAILED