[SOLVED] Cryptography

Author: dammie@seznam.cz (dammie)

Hello, I ve tried encrypting in uniface that i ve founded in documentation help but none of examples is working :( EXAMPLE 1 variables string vEnc raw vrawdata endvariables   vEnc = $encode("BLOWFISH", "~home", "secret key") ;encrypt the data vRawData = $decode("BLOWFISH", vEnc, "secret key") ;decrypt the data klic = $encode("USTRING", vRawData) ;convert the decrypted data from Raw to String   "ERROR=-1791·; MNEM=<UENCERR_GENERAL>·; DESCRIPTION=Encode/decode general error·; COMPONENT=AA0006XO·; PROCNAME=6\DTLF·; TRIGGER=DTLF·; LINE=3·; ADDITIONAL=StreamTransformationFilter: ciphertext length is not a multiple of block size"   EXAMPLE 2 # Generate the RSA private key in the traditional SSLeay format. openssl genrsa -out traditional.pem 2048 OK # Change the private key to PKCS#8 format in PEM encoding. openssl pkcs8 -topk8 -in traditional.pem -inform pem -out myPrivateKey.pem -outform pem To generate the corresponding public key: OK openssl rsa -in myPrivateKey.pem -out myPublicKey.pem -pubout   OK ; Load keys fileload “myPublicKey.pem”, sPubKey   ; Encrypt data by RSA-OAEP encryption scheme with SHA-512 hash ciphertext = $encode("RSA_OAEP_SHA512", plaintext, sPubKey)   "ERROR=-1784·; MNEM=<UENCERR_INVALID_ALGORITHM>·; DESCRIPTION=Invalid algorithm·; COMPONENT=AA0006XO·; PROCNAME=6\DTLF·; TRIGGER=DTLF·; LINE=3"

3 Comments

  1. dammieX said EXAMPLE 1 variables string vEnc raw vrawdata endvariables   vEnc = $encode("BLOWFISH", "~home", "secret key") ;encrypt the data vRawData = $decode("BLOWFISH", vEnc, "secret key") ;decrypt the data klic = $encode("USTRING", vRawData) ;convert the decrypted data from Raw to String "ERROR=-1791·; MNEM=·; DESCRIPTION=Encode/decode general error·; COMPONENT=AA0006XO·; PROCNAME=6\DTLF·; TRIGGER=DTLF·; LINE=3·; ADDITIONAL=StreamTransformationFilter: ciphertext length is not a multiple of block size"

    The variable vEnc needs to be defined as raw. And then the sample will work as expected. Please note that all algorithms (except BASE64, HEX, URL or USTRING) return encoded or encrypted data in the Uniface raw data type. For details see the documentation of $encode.

    dammieX said EXAMPLE 2 # Generate the RSA private key in the traditional SSLeay format. openssl genrsa -out traditional.pem 2048 OK # Change the private key to PKCS#8 format in PEM encoding. openssl pkcs8 -topk8 -in traditional.pem -inform pem -out myPrivateKey.pem -outform pem To generate the corresponding public key: OK openssl rsa -in myPrivateKey.pem -out myPublicKey.pem -pubout OK ; Load keys fileload “myPublicKey.pem”, sPubKey   ; Encrypt data by RSA-OAEP encryption scheme with SHA-512 hash ciphertext = $encode("RSA_OAEP_SHA512", plaintext, sPubKey) "ERROR=-1784·;MNEM=·;DESCRIPTION=Invalid algorithm·;COMPONENT=AA0006XO·;PROCNAME=6\DTLF·;TRIGGER=DTLF·;LINE=3"

    Where did you find this example? When I check the Uniface Library for version 9.6 or 9.7 then the algorithm for the RSA-OAEP encryption scheme with SHA-512 hash is called "RSAES_OAEP_SHA512" and not "RSA_OAEP_SHA512". For details see the example "Encrypting and Decrypting Data Using the Keys" under the topic about "RSA Asymmetric Key Cryptography". Hope this helps. Kind regards, Daniel Iseli Uniface Support


    Author: diseli (daniel.iseli@uniface.com)
  2. In library version 9.5.01 and 9.6.02 as well   ; Load keys fileload “private_key.pem”, sPriKey fileload “public_key.pem”, sPubKey ; Encrypt data by RSA-OAEP encryption scheme with SHA-512 hash ciphertext = $encode(“RSA_OAEP_SHA512”, plaintext, sPubKey) ; Decrypt the ciphertext plaintext = $decode(“RSA_OAEP_SHA512”, ciphertext, sPriKey)   http://unifaceinfo.com/docs/0905/Uniface_Library_HTML/ulibrary/RSA_Cryptography_2F2BFB8028E34C7F8B804CB746AD6717.html


    Author: dammie (dammie@seznam.cz)
  3. dammieX said In library version 9.5.01 and 9.6.02 as well   ; Load keys fileload “private_key.pem”, sPriKey fileload “public_key.pem”, sPubKey ; Encrypt data by RSA-OAEP encryption scheme with SHA-512 hash ciphertext = $encode(“RSA_OAEP_SHA512”, plaintext, sPubKey) ; Decrypt the ciphertext plaintext = $decode(“RSA_OAEP_SHA512”, ciphertext, sPriKey)   http://unifaceinfo.com/docs/0905/Uniface_Library_HTML/ulibrary/RSA_Cryptography_2F2BFB8028E34C7F8B804CB746AD6717.html

    Thanks for the info. So it seems that the mentioned example was incorrect in the older Uniface Library and this has been corrected in the meantime (e.g. 9.6.07 & 9.7.01).


    Author: diseli (daniel.iseli@uniface.com)