1 Generation of hash from private, public key and message
Below an example of document signature is shown and the each one of the used tags are detailed.
Copy
<xsql-script> <body> <!-- Generate private & public key pairs and store in files Should be done once and be preserved for subsequent signatures --> <!-- <security.make.keys algorithm='RSA' key-size='1024'> <file type='absolute' name='private.der' /> <file type='absolute' name='public.der' /> </security.make.keys> --> <set name='message'>2010-03-11;2010-03-11T11:27:08;FAC 001/9;1200.00;PreviousKey</set> <!-- Sign a string and get hash This string is signed by the RSA algorithm using PKCS#1v1.5 EMSA with SHA-1 as the digest algorithm (rsa-sha1). The "Hash" value is the base64-encoded value of the 1024-bit "raw" signature value created by the RSA algorithm. A base64 string consists of the characters [a-zA-Z0-9/+] terminated by none, one or two "=" padding characters. The length should always be divisible by four. For a 1024-bit key, the signature will always result in a 172-byte string of base64 characters ending with exactly one "=" character. The DGCI insists that there should not be any spaces in this string, so make sure there aren't any. --> <set name='hash'> <security.sign.hash algorithm='SHA1withRSA' hash-size='172'> <file type='absolute' name='private.der' /> <file type='absolute' name='public.der' /> <message /> </security.sign.hash> </set> <println>HASH:<hash /></println> <!-- sample verification of a hash --> <set name='verify'> <security.sign.verify algorithm='SHA1withRSA' hash-size='172'> <file type='absolute' name='private.der' /> <file type='absolute' name='public.der' /> <message /> <hash /> </security.sign.verify> </set> <println>VERIFY:<verify /></println> <println>DEISTER PUBLIC KEY:<security.sign.getPublicKey /></println> <!-- How to convert private key from DER (binary) to PEM (ascii), ie : unix/linux# openssl rsa -inform DER -outform PEM -in private_v1.der -out private_v1_pem.txt How to convert pùblic key from DER (binary) to PEM (ascii), ie : unix/linux# openssl rsa -pubin -inform DER -outform PEM -in public_v1.der -out public_v1_pem.txt --> </body> </xsql-script>