Giter VIP home page Giter VIP logo

Comments (6)

flashultra avatar flashultra commented on May 30, 2024 1

In your case you are using Base64 string as data. It should be
var data:Bytes = Base64.decode("79ZE94s1dA86up4W+A0Gpw==");
not Bytes.ofString(....)

Here is a working example:

               var key = Bytes.ofString("rat-moon");
		var des:Des = new Des(key);
		var data:Bytes = Base64.decode("79ZE94s1dA86up4W+A0Gpw==");
		data = des.decrypt(Mode.ECB, data, Padding.PKCS7);
		trace("Decrypted text ECB: "+ data);

from crypto.

rat-moonshine avatar rat-moonshine commented on May 30, 2024 1

Thank you, @flashultra ! That worked like a charm!

Thank you very much for your timely help. It makes a lot of difference. )

from crypto.

flashultra avatar flashultra commented on May 30, 2024

You can use PKCS7 as replacement for PKCS5 padding , it's the same with only difference in block size.
PKCS5 is only for 8-byte block size;
PKCS7 support block size from 1 to 255 bytes.
So PKCS5 padding is a subset of PKCS7 padding for 8 byte block sizes

from crypto.

rat-moonshine avatar rat-moonshine commented on May 30, 2024

@flashultra thank you, for response. If the usage are suppose to be same (PKCS5/7), perhaps you can give me some guidance to overcome the problem I'm facing (?)

With Hurlant.Crypto using same des-ecb and PKCS5 padding, I has following output with these key and values:

trace(hurlant.encrypt(key:"rat-moonshine", value:"secretPassword")); // 79ZE94s1dA86up4W+A0Gpw==

I was trying to decrypt that value (79ZE94s1dA86up4W+A0Gpw==) using Des:

var des:Des = new Des();
data = Bytes.ofHex("79ZE94s1dA86up4W+A0Gpw=="); // key: "rat-moonshine", value: "secretPassword"
data = des.decrypt(ECB, data, PKCS7);
trace("Decrypted text ECB: "+ data);

Unfortunately, it thrown following error on https://github.com/HaxeFoundation/crypto/blob/master/src/haxe/crypto/Des.hx#L329:
[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

from crypto.

flashultra avatar flashultra commented on May 30, 2024

Did you set the key for the Des ( des.init(key,iv) ) ?
Also for Des key size is 56 bits and block size is 64 bits. In your case the key is rat-moon ( as you can test here https://the-x.cn/en-US/cryptography/Des.aspx ) . Probably Hurlant.Crypto cut part of the key when is more than 8 bytes

from crypto.

rat-moonshine avatar rat-moonshine commented on May 30, 2024

Did you set the key for the Des ( des.init(key,iv) ) ?

No. Sorry, I was not clear about the usage but it make sense that we need to feed the key some way.
During the decryption I only has once-encrypted value, and a key.

Thank you, for the test-link (https://the-x.cn/en-US/cryptography/Des.aspx). It seems to decrypt correctly:
image

This time with HaxeFoundation.Crypto, I catch a separate error from https://github.com/HaxeFoundation/crypto/blob/master/src/haxe/crypto/padding/PKCS7.hx#L24:

[Fault] exception, information=Cannot remove 221 bytes, because message is 24 bytes

Can you please check if I'm missing something again in my code (?):

var des:Des = new Des();
var key = Bytes.ofString("rat-moon");
des.init(key);

var data:Bytes = Bytes.ofString("79ZE94s1dA86up4W+A0Gpw==");
data = des.decrypt(ECB, data, PKCS7);
trace("Decrypted text ECB: "+ data);

from crypto.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.