Encryption library

59 views
Skip to first unread message

Anders

unread,
Mar 29, 2023, 2:49:40 PM3/29/23
to Eiffel Users
Hi

I would like to encrypt some text strings in an application. Which pros and cons do you see in the existing Eiffel libraries?

I have found these


which is an extension to this contribution


Then crypto  that is still in the Eiffel unstable library folder:

text/encryption/crypto


Any other?

Regards

Anders



Anders

unread,
Mar 30, 2023, 6:46:51 AM3/30/23
to Eiffel Users
Hi

I tried to use the Chat GPT and asked it this question:

"Please, write Eiffel programming code for encrypting a text string with the Eiffel library Crypto"


And got this answer:, which looks promising except that I can not find the class CIPHER_AES to try it 


====================================================================================
Sure! Here's an example of how you could use the Eiffel library Crypto to encrypt a text string using the Advanced Encryption Standard (AES) algorithm:

class
    EXAMPLE

create
    make

feature
    make
        local
            cipher: CIPHER_AES
            key: ARRAY[CHARACTER_8]
            iv: ARRAY[CHARACTER_8]
            plain_text: STRING
            encrypted_text: STRING
        do
            -- Set the encryption key and initialization vector (IV)
            key := "mysecretkey123456".to_array_8
            iv := "myiv12345678901".to_array_8

            -- Create an instance of the AES cipher with the given key and IV
            cipher := create {CIPHER_AES}.make_with_key_and_iv(key, iv)

            -- Set the plain text to encrypt
            plain_text := "This is some text to encrypt."

            -- Encrypt the plain text
            encrypted_text := cipher.encrypt(plain_text.to_array_8).to_string

            -- Display the encrypted text
            print(encrypted_text)

            -- Decrypt the encrypted text to ensure it can be recovered
            check
                cipher.decrypt(encrypted_text.to_array_8).to_string = plain_text
            end
        end
end


In this example, we create an instance of the CIPHER_AES class and set the encryption key and initialization vector (IV) that will be used for encryption. We then set the plain text that we want to encrypt and use the encrypt method of the cipher to perform the encryption. Finally, we display the encrypted text and use the decrypt method of the cipher to ensure that we can recover the original plain text.

Jocelyn Fiat

unread,
Mar 30, 2023, 9:34:04 AM3/30/23
to eiffel...@googlegroups.com
Side comment, libraries inside the "unstable" library folder are safe to be used, the "unstable" is mostly to say the interfaces may change in the future.
But apart from that they can be used safely.
As a matter of fact, some of them are used in the official libraries (from $ISE_LIBRARY/library/...), and if ever those "unstable" libraries are modified, the libraries from $ISE_LIBRARY/library will also be updated.
In practice, it is unlikely the "unstable" libraries will really break backward compatibility, and if the changes are that deep, they may be duplicated to have a new library.

All that being said, I think it is safe to use the "text/encryption/crypto" library.

There are also interesting classes in the unstable/library/network/openssl library, but it relies on OpenSSL, and is a bit more annoying for deployment.

I hope this was useful.

--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/39e93cdc-5813-43db-a551-bb64b4818009n%40googlegroups.com.


--
Jocelyn
------------------------------------------------------------------------
Eiffel Software
https://www.eiffel.com
Customer support: https://support.eiffel.com
User group: https://groups.google.com/forum/#!forum/eiffel-users
------------------------------------------------------------------------

Anders Persson

unread,
Mar 30, 2023, 10:02:12 AM3/30/23
to eiffel...@googlegroups.com
Thanks

Vänligen

Anders Persson
+46 763 17 23 25
   Bli medlem i Djurens Rätt https://www.djurensratt.se/


 Ge bort världens bästa gåva - träd! https://viskogen.se


You received this message because you are subscribed to a topic in the Google Groups "Eiffel Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/eiffel-users/IQT_kNomGLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/CAFq%2Bd44AVODy0j1j3wb1H2HfH78nAZ4UAvscETpv7NvtndZ6dQ%40mail.gmail.com.

Eric Bezault

unread,
Mar 30, 2023, 4:11:53 PM3/30/23
to eiffel...@googlegroups.com, Anders
On 30/03/2023 12:46, Anders wrote:
> I tried to use the Chat GPT and asked it this question:
>
> "Please, write Eiffel programming code for encrypting a text string with
> the Eiffel library Crypto"
>
>
> And got this answer:, which looks promising except that I can not find
> the class CIPHER_AES to try it

Did you ask Chat GPT where to find this class?

--
Eric Bezault
mailto:er...@gobosoft.com
http://www.gobosoft.com

Anders Persson

unread,
Mar 31, 2023, 8:25:41 AM3/31/23
to eiffel...@googlegroups.com
Yes Eric

This is my conversation with it, my questions in bold including the spelling errors I did. I asked the question directly so it was in one session.

"Thanks, where can i find the CIPHER_AES class?"


The CIPHER_AES class is part of the Eiffel Crypto library, which is not included by default with the EiffelStudio development environment. To use the CIPHER_AES class and other classes from the Crypto library, you will need to download and install the library first.

You can download the Crypto library from the Eiffel Software website at the following link:

https://www.eiffel.com/cryptolib/

Once you have downloaded and installed the Crypto library, you can add it to your EiffelStudio project and import the CIPHER_AES class like this:

import
    crypto.cipher.aes

This will allow you to use the CIPHER_AES class and other classes from the Crypto library in your Eiffel code.


"tjhelink https://www.eiffel.com/cryptolib/ does not work and Eiffel does not have an import clause"

I apologize for the confusion. It seems that the Eiffel Crypto library is no longer available on the Eiffel Software website.

Regarding the import clause, Eiffel does not have an import keyword as in other programming languages like Java or Python. Instead, Eiffel uses a concept called "clusters" to group related classes together.

To use a class from another cluster in your Eiffel code, you need to add that cluster to your project. This can be done using the EiffelStudio IDE by right-clicking on your project in the project toolbar and selecting "Add Cluster" from the context menu.

Once you have added the Crypto library cluster to your project, you can create an instance of the CIPHER_AES class and use its methods to encrypt and decrypt text strings. Here's an example:

class
    EXAMPLE

create
    make

feature
    make
        local
            cipher: CIPHER_AES
            key: ARRAY[CHARACTER_8]
            iv: ARRAY[CHARACTER_8]
            plain_text: STRING
            encrypted_text: STRING
            decrypted_text: STRING

        do
            -- Set the encryption key and initialization vector (IV)
            key := "mysecretkey123456".to_array_8
            iv := "myiv12345678901".to_array_8

            -- Create an instance of the AES cipher with the given key and IV
            create cipher.make_with_key_and_iv(key, iv)


            -- Set the plain text to encrypt
            plain_text := "This is some text to encrypt."

            -- Encrypt the plain text
            encrypted_text := cipher.encrypt(plain_text.to_array_8).to_string

            -- Display the encrypted text
            print(encrypted_text)

            -- Decrypt the encrypted text
            decrypted_text := cipher.decrypt(encrypted_text.to_array_8).to_string

            -- Display the decrypted text
            print(decrypted_text)
        end
end


In this example, we create an instance of the CIPHER_AES class using the make_with_key_and_iv creation procedure, which takes the encryption key and initialization vector as arguments. We then use the encrypt method of the cipher to encrypt the plain text, and the decrypt method to decrypt the encrypted text. Note that we convert the text strings to ARRAY[CHARACTER_8] before passing them to the cipher, and convert the resulting ARRAY[CHARACTER_8] back to STRING for display.

Vänligen

Anders Persson
+46 763 17 23 25
   Bli medlem i Djurens Rätt https://www.djurensratt.se/


 Ge bort världens bästa gåva - träd! https://viskogen.se

--
You received this message because you are subscribed to a topic in the Google Groups "Eiffel Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/eiffel-users/IQT_kNomGLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to eiffel-users...@googlegroups.com.

Anders Persson

unread,
Apr 10, 2023, 12:17:36 PM4/10/23
to Eiffel Users
Hi

I am already using openssl so I will try that path.

Would it be a good starting point to start with this test case as an example 

test_gcm_tag_encrypt_decrypt

Regards 

Anders 


You received this message because you are subscribed to a topic in the Google Groups "Eiffel Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/eiffel-users/IQT_kNomGLA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/CAFq%2Bd44AVODy0j1j3wb1H2HfH78nAZ4UAvscETpv7NvtndZ6dQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages