Quick Links: Gideros Home | Download Gideros | Developer Guide
Cryptography
  • Hello to everyone,
    I have a problem with Cryptography.md5 that I do not understand.
    When I use this function, the returning result (16 byte string) is out of specification. How do I get the standard end result?

    For example:
    Print(Cryptography.md5("a")) -----> �u�����1�iw&a
    or
    dataSaver.saveValue("|D|somevalue", Cryptography.md5("a")) -----> {"data":{"|D|somevalue":"\fÁu¹Àñ¶¨1Ùâiw&a"}}

    The actual result should be 0cc175b9c0f1b6a831c399e269772661
    How can I get this result?

    Where am I making mistakes? Can you help with the code sample?

    Note:
    I am also having the same problem between Gideros Cryptography.aesEncrypt and .NET System.Security.Cryptography. The key and IV are the same as the result of AES128 which is not the same.
  • hgy29hgy29 +1 -1 (+2 / -0 )
    Maintainer
    Hi @turker2000,

    Cryptography.md5() returns the 16 bytes hash in binary format, that is a string of 16 bytes, while you expect it to be hex-string encoded (32 characters).

    Try this:
    print(("%02x"):rep(16):format(Cryptography.md5("a"):byte(1,16)))

    Likes: turker2000, antix

  • Thank you very much for your help. Could you give an idea for AES too? The results do not hold the same. Here's an example code I use for .NET to give you an idea.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    using System.Security.Cryptography;
     
    namespace cso2_AES_sifreleme
    {
    class AESSinif
    {
    private const string AES_IV = @"0123456789abcdef";
    private string aes_anahtar = @"1234567890123456";
     
     
    public string AESsifrele(string metin)
    {
    AesCryptoServiceProvider aes_saglayici = new AesCryptoServiceProvider();
    /*
    Şifreleme yöntemi olarak AES şifreleme yöntemini seçiyoruz.
    */
     
    aes_saglayici.BlockSize = 128;
    /*
    AES bloklar halinde şifreleme yapar.
    Biz de bloklama yöntemini belirliyoruz.
    */
     
    aes_saglayici.KeySize = 128;
    /*
    AES şifreleme metodunda anahtar ile şifreleme yapılıyor.
    Anahtar boyutları 128, 192 ve 256 olabilir.
    */
     
    aes_saglayici.IV = Encoding.UTF8.GetBytes(AES_IV);
    //IV = Initial Vector
    aes_saglayici.Key = Encoding.UTF8.GetBytes(aes_anahtar);
    aes_saglayici.Mode = CipherMode.CBC;
    aes_saglayici.Padding = PaddingMode.PKCS7;
     
    byte[] kaynak = Encoding.Unicode.GetBytes(metin);
    /*
    Metni byte dizisine çeviriyoruz.
    */
    using (ICryptoTransform sifrele = aes_saglayici.CreateEncryptor())
    {
    byte[] hedef = sifrele.TransformFinalBlock(kaynak, 0, kaynak.Length);
    return Convert.ToBase64String(hedef);
    }
    }
     
     
    public string AESsifreCoz(string sifreliMetin)
    {
    AesCryptoServiceProvider aes_saglayici = new AesCryptoServiceProvider();
    aes_saglayici.BlockSize = 128;
    aes_saglayici.KeySize = 128;
    aes_saglayici.IV = Encoding.UTF8.GetBytes(AES_IV);
    aes_saglayici.Key = Encoding.UTF8.GetBytes(aes_anahtar);
    aes_saglayici.Mode = CipherMode.CBC;
    aes_saglayici.Padding = PaddingMode.PKCS7;
     
    byte[] kaynak = System.Convert.FromBase64String(sifreliMetin);
    //byte[] kaynak = Encoding.UTF8.GetBytes(sifreliMetin);
     
    using (ICryptoTransform decrypt = aes_saglayici.CreateDecryptor())
    {
    byte[] hedef = decrypt.TransformFinalBlock(kaynak, 0, kaynak.Length);
    return Encoding.Unicode.GetString(hedef);
    }
    }
     
    }
    }


    the results are the same with Gideros ---> ÓÙğ±\u0011Ù`qú§\\\u00161»\u0016„
    The result produced with .NET ----> z6rzKFeAyyNZZOQMRCHvnQ==
  • hgy29hgy29 +1 -1
    Maintainer
    At first sight you didn't encode the result to base64 in gideros while do it in .NET
  • JoanWileJoanWile +1 -1
    Member
    this is a delightful post, thank you very much for posing this problem, it was very interesting to read this, it will be interesting to find out how you solved this problem?
    you can buy app store reviews on our website from professionals
  • antixantix +1 -1
    Member
    @JoanWile, please don't post comments when all you seem to be doing is wanting people to buy reviews on your site. This forum is for Gideros users, not people selling junk reviews, thanks :)
    Check out my DevBlog, my GitHub, and my games Falling Animals | Breaky Wall | Exetor

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters