Home Forums Development AES-256 encryption

Viewing 1 reply thread
  • Author
    Posts
    • #13408
      Mohammad IkmailMohammad Ikmail
      Participant

      Hi,

      We have a requirement to encrypt the values using AES – AES/CBC/PKCS5Padding (for that we got the AES encryption file) before sending it over the network (to call a rest api), may you please suggest the best way to achieve this.

      Thanks

      0
    • #13439
      Vassiliy Iordanovvi
      Participant

      Do you intend to encrypt individual values and then use them in a message, or you have to encrypt the whole HTTP request body?
      In either case, on the server you can access cryptography classes provided by the JDK.
      You can place the encryption code in a new Java class and then invoke e.g. a static method, or you can invoke all the methods directly from Scheme.

      For example:

      (import ‘javax.crypto.Cipher ‘javax.crypto.spec.IvParameterSpec
      ‘nexj.core.util.RandUtil ‘nexj.core.util.Binary)

      (define (encrypt-my-value s key)
      (define cipher (javax.crypto.Cipher’getInstance “AES/CBC/PKCS5Padding”))
      (cipher’init (javax.crypto.Cipher’ENCRYPT_MODE) key
      (javax.crypto.spec.IvParameterSpec’new ((nexj.core.util.RandUtil’secureRandom)’generateSeed 16)))
      (nexj.core.util.Binary’new (cipher’doFinal ((ifnull s “”)’getBytes “UTF-8”)))
      )

      0
Viewing 1 reply thread
  • You must be logged in to reply to this topic.