Comments (6)
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.
Thank you, @flashultra ! That worked like a charm!
Thank you very much for your timely help. It makes a lot of difference. )
from crypto.
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.
@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.
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.
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:
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)
- Travis : Type not found : haxe.crypto.Aes HOT 3
- Does it support Aes-256 bit HOT 2
- Incorrect result for AES CTR 128 Bit HOT 7
- Error "haxe.io.Bytes should be String" HOT 3
- SHA-256 is wrong on PHP (new Haxelib release needed) HOT 8
- Haxelib says latest version is 1.0.2-alpha, but 0.4.0 was published more recently? HOT 2
- Haxe-crypto HOT 9
- [Neko specific issue] Uncaught exception - load.c(398) : Invalid module : main.n HOT 4
- PHP test failures HOT 2
- Incremental hashing for haxe.crypto.*
- Enhancement Request: SHA-512 HOT 1
- Sha256 Unicode test failed HOT 7
- BCrypt is too slow HOT 10
- [eval] Ripemd-160 test failed on Appveyor HOT 2
- Compatibility for Haxe 3 HOT 5
- [feature request] rsa support HOT 4
- Publish on haxelib HOT 2
- Use Vector instead of Array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crypto.