MCrypt rijndael-128 to OpenSSL aes-128-ecb conversion

前端 未结 3 1372
攒了一身酷
攒了一身酷 2020-11-29 07:47

Since Mcrypt is deprecated, I want to use OpenSSL instead in my code since we already using php 7.0.17 in our server and there\'s no tell when they upgrade

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 08:22

    Most likely the key was expected to be used as hex (it already is in hex format) not as a string to be converted to hex.


    mcrypt:

    mcrypt does not support standard PKCS#7 (née PKCS#5) padding, only non-standard null padding but the padding is being explicitly added prior to mcrypt.

    The encryption v7IXp5vVaFVXXlt/MN8BVw== is the correct encryption based on PKCS#7 padding. ECB mode and the key as a string.

    See: mcrypt - AES CALCULATOR.

    In hex, notice the data padding is clearly visible:
    key: 6130613765373939376236643566636435356634623563333236313162383763
    data: 736D616C6C310A0A0A0A0A0A0A0A0A0A
    encrypted: BFB217A79BD56855575E5B7F30DF0157

    In Base64:
    encrypted: v7IXp5vVaFVXXlt/MN8BVw==


    OpenSSL:

    Notice the key is 256-bits but the OpenSSL call with "aes-128-ecb" seems to imply a 128-but key. So the keys don't match.

    See: OpenSSL - AES CALCULATOR

    In hex, notice the data padding is clearly visible:
    key: 61306137653739393762366435666364
    data: 736D616C6C310A0A0A0A0A0A0A0A0A0A
    encrypted: 4B1277F8475A788B59C77FC4C064D46F

    In Base64:
    encrypted: SxJ3+EdaeItZx3/EwGTUbw==

提交回复
热议问题