Giter VIP home page Giter VIP logo

crypto's Introduction

GitHub Build Status

Cross platform cryptographic functions for Haxe 4 and 3

This brings cryptographic functions for Haxe 4, with -lib crypto after having installed it with haxelib install crypto.

It is also usable on Haxe 3, where there is already a haxe.crypto package containing Adler32, Base64, BaseCode, Crc32, HMac, Md5, Sha1, Sha224, Sha256. Using this library on Haxe 3 with -lib crypto will overload the haxe.crypto package and allow support for Aes, BCrypt, BlowFish, Des, Pbkdf2, Ripemd160, Sha384, Sha512, TripleDes, TwoFish in addition to the previous 9 classes.

Supported algorithms

Other algorithms

Block cipher mode of operation

  • ECB
  • CBC
  • PCBC
  • CFB
  • OFB
  • CTR

Padding

  • AnsiX923
  • BitPadding / ISO 9797-1 / ISO7816-4 / One and zeros
  • ISO10126 / Random padding
  • NoPadding
  • NullPadding / Zero byte padding
  • PKCS7 ( support PKCS#5 padding)
  • SpacePadding
  • TBC ( Trailing-Bit-Compliment padding )

Security Considerations

This code has not been subjected to a formal, paid, security audit. This library can be use with a degree of safety equivalent to any other encryption library written in pure Haxe.

When using this library please keep the following in mind:

  • Cryptography is hard. Please review and test this code before depending on it for critical functionality.
  • Haxe can compile to different languages , so the execution of this code depends on trusting a very large set of tools and systems.
  • Be careful about the source from which you download the library.
  • Use "native" functionality where possible. This can be critical when dealing with performance and security.
  • Understand possible attacks against cryptographic systems. For instance side channel and timing attacks may be possible due to the difficulty in implementing constant time algorithms in different algorithms and for different targets.
  • Certain features within this library may have a lower vulnerability to attacks, this could includes features that deal with data format manipulation or those features that do not play a role in communication.

Questions

Should I be using Haxe Crypto for something that actually needs to be secured?

  • Yes, you can use it for different tasks. Just because this library doesn't have an formal, paid, security audit check doesn't mean it's insecure. Some algorithms can be susceptible on side channels and timing attacks when the attacker generates millions of combinations (encryption and decryption) and tries to guess the password, but this does not mean, firstly, that it is an easy task to hack an algorithm, and secondly, not for all algorithms here such attacks can be used. The hacking process is still not that easy task, especially if you use advanced algorithms and long encryption , decryption keys and passwords. Just an example, obfuscation is also a process for protection. Is it 100% hack protected? No. Is it widely used for protection? Yes

Where is it safe to use this library?

  • Well, if you are protecting financial and banking transactions, I will recommend you to use audited cryptographic software . In other cases (such as game resources, game communication (not financial) and even login forms, this library should give you enough protection. But for this, you should always use long keys and proven algorithms Don't use old unsecure algorithms like DES or RC4 (it's here for backwards compatibility)

Are OpenSSL, Nacl 100% bug free and secured?

  • Various bugs are found in them over time, as in most, if not all, security libraries. So are they 100% secure/bug free? I don't think so. Bugs will likely appear over time. Should I use them then? Of course, you should definitely use it if you need them.

Is this library not maintained at all ?

  • This is not true. There is a regular updates that brings better performance and new algorithms. All pull request a timely review and merged. Also all algorithms are properly implemented and include many tests for all platforms (check here https://github.com/HaxeFoundation/crypto/tree/master/tests/src/unit/crypto) If you wish, you could add more test by opening pull request

Usage

AES Encryption

   var aes : Aes = new Aes();
   
   var key = Bytes.ofHex("603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4");
   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var iv:Bytes = Bytes.ofHex("4F021DB243BC633D7178183A9FA071E8");
   
   aes.init(key,iv);
   
   // Encrypt
   var data = aes.encrypt(Mode.CTR,text,Padding.NoPadding);
   trace("Encrypted text: "+ data.toHex());
   
   // Decrypt
   data = aes.decrypt(Mode.CTR,data,Padding.NoPadding);
   trace("Decrypted text: "+ data);

Blowfish

   var blowFish  : BlowFish = new BlowFish();
   
   var key = Bytes.ofHex("E0FEE0FEF1FEF1FE");
   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var iv:Bytes = Bytes.ofHex("7FC38460C9225873");
   
   blowFish.init(key,iv);
   
   // Encrypt
   var data = blowFish.encrypt(Mode.PCBC,text,Padding.PKCS7);
   trace("Encrypted text: "+ data.toHex());
   
   // Decrypt
   data = blowFish.decrypt(Mode.PCBC,data,Padding.PKCS7);
   trace("Decrypted text: "+ data);

Twofish

   var twoFish  : TwoFish = new TwoFish();
   
   var key = Bytes.ofHex("ff08e2dcca459835ac30c39548ae848157ba5fdcc8e4977efc26c0d1cc7a25cb");
   var text = Bytes.ofHex("06051a69c4a72fa8b205ebdca3add79d5e904b5e9e6d08ed60233ad28b9540ba");
   
   twoFish.init(key);
   
   // Encrypt
   var data = twoFish.encrypt(Mode.ECB,text,Padding.NoPadding);
   trace("Encrypted text: "+ data.toHex());
   
   // Decrypt
   data = twoFish.decrypt(Mode.ECB,data,Padding.NoPadding);
   trace("Decrypted text: "+ data.toHex());

Triple DES / 3Des

   var tdes : TripleDes = new TripleDes();
   
   var key = Bytes.ofHex("2BD6459F82C5B300952C49104881FF482BD6459F82C5B300");
   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var iv:Bytes = Bytes.ofHex("A015E0CFA1FED3B5");
   
   tdes.init(key,iv);
   
    // Encrypt
   var data = tdes.encrypt(Mode.OFB,text,Padding.NoPadding);
   trace("Encrypted text: "+ data.toHex());
   
   // Decrypt
   data = tdes.decrypt(Mode.OFB,data,Padding.NoPadding);
   trace("Decrypted text: "+ data);

DES

   var des:Des = new Des();
   
   var key = Bytes.ofHex("9816854577667254");
   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var iv:Bytes = Bytes.ofHex("69cf9d79757adcab");
   
   des.init(key,iv);
   
    // Encrypt
   var data = des.encrypt(Mode.CTR,text,Padding.NoPadding);
   trace("Encrypted text: "+ data.toHex());
   
   // Decrypt
   data = des.decrypt(Mode.CTR,data,Padding.NoPadding);
   trace("Decrypted text: "+ data);

BCrypt

   var salt = BCrypt.generateSalt(10,BCrypt.Revision2B); // Example: $2b$10$xB5TcOrSHD2quBMES0W8aO
    
   var dataText = BCrypt.encode("Haxe - The Cross-platform Toolkit",salt);
   trace("BCrypt: "+dataText); // Example: $2b$10$xB5TcOrSHD2quBMES0W8aOrxTs3ONJQzqYIe0l.s1BHO6KoYUY5IS
   
   var match = BCrypt.verify("Haxe - The Cross-platform Toolkit",dataText);
   trace("Match: "+match);

Hmac with MD5 / SHA1 / SHA224 / SHA256 / SHA384 / SHA512

   var hmacMd5 = new Hmac(MD5);
   var hmacSha1 = new Hmac(SHA1);
   var hmacSha224 = new Hmac(SHA224);
   var hmacSha256 = new Hmac(SHA256);
   var hmacSha384 = new Hmac(SHA384);
   var hmacSha512 = new Hmac(SHA512);

   var key = ofHex("c8c2c9d386b63964");
   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var data = hmacMd5.make(key,text);
   trace("HMac MD5: "+data.toHex());
   
   data = hmacSha1.make(key,text);
   trace("HMac Sha1: "+data.toHex());

   data = hmacSha224.make(key,text);
   trace("HMac Sha224: "+data.toHex());

   data = hmacSha256.make(key,text);
   trace("HMac Sha256: "+data.toHex());
   
   data = hmacSha384.make(key,text);
   trace("HMac Sha384: "+data.toHex());
   
   data = hmacSha512.make(key,text);
   trace("HMac Sha512: "+data.toHex());

SHA1

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Sha1.encode("Haxe - The Cross-platform Toolkit");
   trace("Sha1: "+dataText);
   
   var dataBytes = Sha1.make(text);
   trace("Sha1: "+dataBytes.toHex());

SHA224

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Sha224.encode("Haxe - The Cross-platform Toolkit");
   trace("Sha224: "+dataText);
   
   var dataBytes = Sha224.make(text);
   trace("Sha224: "+dataBytes.toHex());

SHA256

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Sha256.encode("Haxe - The Cross-platform Toolkit");
   trace("Sha256: "+dataText);
   
   var dataBytes = Sha256.make(text);
   trace("Sha256: "+dataBytes.toHex());

SHA384

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Sha384.encode("Haxe - The Cross-platform Toolkit");
   trace("Sha384: "+dataText);
   
   var dataBytes = Sha384.make(text);
   trace("Sha384: "+dataBytes.toHex());

SHA512

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Sha512.encode("Haxe - The Cross-platform Toolkit");
   trace("Sha512: "+dataText);
   
   var dataBytes = Sha512.make(text);
   trace("Sha512: "+dataBytes.toHex());

Ripemd-160

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   
   var rpmd = Ripemd160.encode("Haxe - The Cross-platform Toolkit");
   trace("Ripemd-160: "+rpmd);
   
   var rpmd = Ripemd160.make(text);
   trace("Ripemd-160: "+rpmd.toHex());
   
   var rpmd = new Ripemd160();
   rpmd.addBytes(text,0,text.length);
   var rdata = rpmd.finish();
   trace("Ripemd-160: "+rdata.toHex());

PBKDF2

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var salt = Bytes.ofString("salt");
   
   // Support: MD5, SHA1,	SHA224, SHA256, SHA384, SHA512, RIPEMD160
   var pbkdf2 : Pbkdf2 = new Pbkdf2(SHA1);
   var data = pbkdf2.encode(text,salt,4096,20);
   trace("PBKDF2: "+data.toHex());

Salsa20

   var key = Sha256.make(Bytes.ofString("secret key"));
   var nonce = Bytes.ofHex("288FF65DC42B92F9");
   var msg = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var salsa = new Salsa20();
   salsa.init(key,nonce);
   var data = salsa.encrypt(msg);
   trace("Salsa20 encrypt: "+data.toHex());

   var salsaDecrypt =  new Salsa20();
   salsaDecrypt.init(key,nonce);
   var plainData = salsaDecrypt.decrypt(data);
   trace("Salsa20 decrypt: "+ plainData.toString());

   salsa.reset();
   plainData = salsa.decrypt(data);
   trace("Salsa20 decrypt ( with reset ) : "+ plainData.toString());

   salsa.seek(0);
   plainData = salsa.decrypt(data);
   trace("Salsa20 decrypt ( with seek position ) : "+ plainData.toString());

XSalsa20

   var key = Sha256.make(Bytes.ofString("secret key"));
   var nonce = Bytes.ofHex("9E645A74E9E0A60D8243ACD9177AB51A1BEB8D5A2F5D700C");
   var msg = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var xsalsa = new XSalsa20();
   xsalsa.init(key,nonce);
   var data = xsalsa.encrypt(msg);
   trace("XSalsa20 encrypt: "+data.toHex());

   var xsalsaDecrypt =  new XSalsa20();
   xsalsaDecrypt.init(key,nonce);
   var plainData = xsalsaDecrypt.decrypt(data);
   trace("XSalsa20 decrypt: "+ plainData.toString());

ChaCha

   var key = Sha256.make(Bytes.ofString("secret key"));
   var nonce = Bytes.ofHex("0F1E2D3C4B596877");
   var msg = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var chaCha = new ChaCha();
   chaCha.init(key,nonce);
   var data = chaCha.encrypt(msg);
   trace("ChaCha encrypt: "+data.toHex());

   var chaChaDecrypt =  new ChaCha();
   chaChaDecrypt.init(key,nonce);
   var plainData = chaChaDecrypt.decrypt(data);
   trace("ChaCha decrypt: "+ plainData.toString());

RC4 ( ARC4 )

   var key = Bytes.ofHex("a99c5476d5e5d61d425c01fa29632171");
   var msg = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var rc4 = new RC4();
   rc4.init(key);
   var data = rc4.encrypt(msg);
   trace("RC4 encrypt: "+data.toHex());

   rc4.init(key);
   var plainData = rc4.decrypt(data);
   trace("RC4 decrypt: "+ plainData.toString());

SCrypt

   var salt = Bytes.ofHex("536F6469756D43686C6F72696465");
   var password = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var scrypt:SCrypt = new SCrypt();
   var data = scrypt.hash(password, salt, 1024, 8, 1, 64);
   trace("SCrypt hash: "+data.toHex());

Poly1305

   var key = Sha256.make(Bytes.ofString("secret key")); //32 bytes key
   var msg = Bytes.ofString("Haxe - The Cross-platform Toolkit");
  
   var poly1305 = new Poly1305();
   var data = poly1305.encode(msg,key); 
   trace("Poly1305 encrypt: "+data.toHex());
   
   // Verify
   var verify = poly1305.verify(msg,key,data);
   trace("OK: "+verify);

   // Streaming API
   var poly1305 = new Poly1305();
   poly1305.init(key);
   poly1305.update(msg, 0, msg.length);
   msg = Bytes.ofString("Haxe can build cross-platform applications.");
   poly1305.update(msg, 0, msg.length);
   var data = poly1305.finish();
   trace("Poly1305 encrypt: "+ data.toHex());

Md5

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    
   var dataText = Md5.encode("Haxe - The Cross-platform Toolkit");
   trace("Md5: "+dataText);
   
   var dataBytes = Md5.make(text);
   trace("Md5: "+dataBytes.toHex());

Adler32

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var data = Adler32.make(text);
   trace("Adler32: "+data);

Crc32

   var text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
   var data = Crc32.make(text);
   trace("Crc32: "+data);

crypto's People

Contributors

andyli avatar apprentice-alchemist avatar flashultra avatar jens-g avatar kevinresol avatar ncannasse avatar realyuniquename avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crypto's Issues

Enhancement Request: SHA-512

Request

Add a SHA-512 implementation to the package haxe.crypto.

Details

This implementation should be based on the NIST FIPS 180 Secure Hash Standard:
https://csrc.nist.gov/pubs/fips/180-4/upd1/final
https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf

This implementation should be modeled after the existing class haxe.crypto.Sha256 as a template for usage, exposing similar static functions encode(String):String and make(haxe.io.Bytes):haxe.io.Bytes, and including similar designs/patterns for other non-exposed functions/fields.

Suggested Code Change

I can start off by submitting a pull request to show what this would look like.

Additional Thoughts

A shared base class or even just shared interfaces should also be added for defining any overlaps between the various SHA classes. This is not being included as part of this request since that effort would ideally be done under a different ticket w/ a larger scope, as it would involve refactoring all existing SHA implementations.

Does it support Aes-256 bit

It said support Aes , but does not mention which one
does the default is 256 bit , or which one ?
if supported , how to set it ?

Incremental hashing for haxe.crypto.*

Right now haxe.crytop.Sha256 and friends require all the data to be hashed to be in RAM before hashing. This means it cannot be used to eg hash large files. It would be good to provide an incremental hashing function with .update() method as is found in other ecosystems.

[Neko specific issue] Uncaught exception - load.c(398) : Invalid module : main.n

Hello! I'm encountering an issue with the library. After successfully compiling the code, I'm trying to execute the resulting neko file. However, I'm getting an Uncaught exception - load.c(398) : Invalid module : main.n error. This seems to be a neko-specific issue rather than a problem with the library itself. This happened once I imported the haxe.crypto.Poly1305 library into the project

Steps to reproduce:

  1. Download the library using haxelib git crypto https://github.com/HaxeFoundation/crypto
  2. Compile the code using haxe -main Main --neko main.n -L crypto.
  3. Attempt to execute the neko file using neko main.n.
  4. Get the Uncaught exception - load.c(398) : Invalid module : main.n error

Expected behavior:
The neko file should execute without any errors.

Actual behavior:
An Uncaught exception - load.c(398) : Invalid module : main.n error is encountered.

Additional information:
Operating system: Windows 10 22H2
Haxe version: 4.2.5
Neko version: 2.3.0

Any kind of help would be appreciated, thank you! :3

SHA-256 is wrong on PHP (new Haxelib release needed)

Haxe 4.2.4 / PHP 8.1.0 with crypto 1.0.2-alpha.

If I generate a SHA-256 hash code using the PHP hash function:

trace(php.Global.hash("sha256", "FooBar123"));
// 77853caf12f9d2020f3715accd9c7b15738705daf03650906af17a7a655c2ee2

If I generate the same SHA-256 hash code using the haxe.crypto.Sha256 class... without the crypto library enabled:

trace(haxe.crypto.Sha256.encode("FooBar123"));
// 77853caf12f9d2020f3715accd9c7b15738705daf03650906af17a7a655c2ee2

If I generate the same SHA-256 hash code using the haxe.crypto.Sha256 class... with the crypto library enabled:

trace(haxe.crypto.Sha256.encode("FooBar123"));
// c029836676a2e454cdafcd48507c211c8d52f0e06db9bd6d7a409fcf970f57c6 => What?!?

It seems that PR #12 was not released on Haxelib...
https://lib.haxe.org/p/crypto/1.0.2-alpha/files/crypto-1.0.2-alpha/src/haxe/crypto/Sha256.hx

...and it seems that there is a difference between the implementations provided by this package and the Haxe standard library.

Need PKCS5 Padding

Please provide support for PKCS5 padding. Currently it supports only PKCS7.

A reference to PKCS5 can be found on sowyiz.crypto.

[eval] Ripemd-160 test failed on Appveyor

First word from the test pass, all other failed.
The problem is not reproducible from my side ( on my PC ) and for that reason don't know how to fix it.
The only things which is different is using of BytesBuffer class and clear with new BytesBuffer();

Publish on haxelib

It would be nice to publish this to haxelib. It'll probably also need a haxelib.json file.

Sha256 Unicode test failed

I did some test with string รฉใ‚๐Ÿ˜‚ and this give different length 9 and 4 with different Haxe 4 version.
What should be the correct length ? I think this is the problem for Sha256 particulary here in s.length) :

var h = sh.doEncode(str2blks(s), s.length*8);

Sha256
Test string: รฉใ‚๐Ÿ˜‚
Length: 9
Version: Haxe 4.0.0-preview.4+1e3e5e016
Result : d0230b8d8ac2d6d0dbcee11ad0e0eaa68a6565347261871dc241571cab591676
Correct !

Test string: รฉใ‚๐Ÿ˜‚
Length: 4
Version: Haxe development
Result : e662834bdc1a099b9f7b8d97975a1b1d9b6730c991268bba0e7fe7427e68be74
Incorrect

Travis : Type not found : haxe.crypto.Aes

AesTest.hx failed on import with error "Type not found : haxe.crypto.Aes".

I think the problem is because haxe compiler search in his repository in haxe.crypto package , but Aes class exist in same package haxe.crypto , but in crypto repository .

I set classpath in https://github.com/HaxeFoundation/crypto/blob/master/tests/compile.hxml to be "src" and "../src" , but it doesn't help.

For me , package haxe.crypto is logical choice for crypto repository data, for severa reasons:

  1. If old projects install crypto package , they still can use Hmac, Sha256 , Sha224 without to change any code.
  2. Crypto repository can be consider as crypto+ against haxe.crypto in haxe repository and both can work in parallel

Haxelib says latest version is 1.0.2-alpha, but 0.4.0 was published more recently?

It appears that you went backwards in version numbering, which is potentially confusing and dangerous (especially for an encryption library, which needs to be held to a high standard, considering the security implications). Luckily, it seems that haxelib install crypto installs version 0.4.0 correctly, but the Haxelib website still says that 1.0.2-alpha is the newest version (which it isn't, obviously).

I hope that you will consider making the next published version be 1.5.0 or 2.0.0 (or anything higher than 1.0.2) instead of 0.5.0.

Incorrect result for AES CTR 128 Bit

import haxe.io.*;
import haxe.crypto.*;

class Main {
  static function main() {
    var decrypted = Bytes.ofHex('124c4e4243484b473030303531320000000c03000000000000000000001b03064327020c850308200002095e020b160a0d00ff00e7000080000097');
    var key = Bytes.ofHex('79ddd935f38f2a99cead496b9ef75f4d');
    var iv = Bytes.ofHex('b5cb4d8dd2c2fc705e10a825000043fd');
    var encrypted = Bytes.ofHex('6ac6e4f866d87942eeb002baf7b2c9d7f600bc639f30c90baffc20d7eacb83472a20d03f60e9348a651f138ffb44e27306fd3b39b5595086b491ac');
    var aes = new Aes();
    aes.init(key, iv);
    
    
    trace('encrpyt:    ${decrypted.toHex()}');
    trace('with key:   ${key.toHex()}');
    trace('with iv:    ${iv.toHex()}');
    var enc = aes.encrypt(CTR, decrypted, NoPadding);
    trace('expected:   ${encrypted.toHex()}');
    trace('calculated: ${enc.toHex()}');
    trace('match:      ' + (enc.toHex() == encrypted.toHex()));
  }
} 

result:

encrpyt:    124c4e4243484b473030303531320000000c03000000000000000000001b03064327020c850308200002095e020b160a0d00ff00e7000080000097
with key:   79ddd935f38f2a99cead496b9ef75f4d
with iv:    b5cb4d8dd2c2fc705e10a825000043fd
expected:   6ac6e4f866d87942eeb002baf7b2c9d7f600bc639f30c90baffc20d7eacb83472a20d03f60e9348a651f138ffb44e27306fd3b39b5595086b491ac
calculated: 6ac6e4f866d87942eeb002baf7b2c9d7f600bc639f30c90baffc20d7eacb83472a20d03f60e9348a651f138ffb44e2732a3858f61514161820ae9c
match:      false

The expected value is obtained from this or this site. Note that the value generated by this lib is correct up to the 48-th byte (total is 59 bytes), so I think the issue may be related to 16-byte blocks / paddings.

BCrypt is too slow

BCrypt is way too slow . For rounds=10 should give ~10 hashes/sec , now give 1 hash for 10 sec.

These is because Feistel function ( i.e. f( x : Int ) ) .
For some reason bit shift operation are too slow in Haxe or it's maybe other specific issue.

Simple bcrypt hash for 10 rounds with salt = $2a$10$/OxwMgmw06Zkhz/SLgc.4u and text = some_text will take about 10 seconds.
Final result is : $2a$10$/OxwMgmw06Zkhz/SLgc.4uYyFJfaVs5/O.1.8Z9dPYIDxio8Jpc6W

[feature request] rsa support

Like the titel says: Rsa Support.

First stuff that we need is a bigint class.
i don't know where it fits. But i think BigInt should be directly in the core haxe repo?

Error "haxe.io.Bytes should be String"

Description

I want to secure session related data by encrypting it, and being able to retreive it by decrypting it.

I ran into an error trying to run this snippet (taken from the README example)

import haxe.io.Bytes;
import haxe.crypto.mode.Mode;
import haxe.crypto.padding.Padding;
import haxe.crypto.Aes;

@:nullSafety(Strict)
final class Main {
  static var key = "";

  public static function main() {
    final aes : Aes = new Aes();

    final key = Bytes.ofHex("603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4");
    final text = Bytes.ofString("Haxe - The Cross-platform Toolkit");
    final iv: Bytes = Bytes.ofHex("4F021DB243BC633D7178183A9FA071E8");

    aes.init(key,iv);

    // Encrypt
    final data = aes.encrypt(Mode.CTR, text, Padding.NoPadding);
  }
}

And I get this error:

haxe.io.Bytes should be String

Around the last line (I supposed it is related to the second parameter.

Additional data

  • Haxe version: 4.1.5
  • Target: PHP
  • Package version: 0.3.0 and 1.0.2-alpha
  • OS: Alpine (over Docker for Windows 10)

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.