xor_dart

Creator: coderz1093

Last updated:

0 purchases

xor_dart Image
xor_dart Images
Add to Cart

Description:

xor dart

Symmetric Cipher XOR #

A pure dart XOR cipher library, support encryption and decryption with or without a symmetric secret key.
Usage example #
1. with a secret key
import 'package:xor_dart/xor_dart.dart';

void main() {
var xor = Xor('_a_random_key_');

var plain = 'You are so handsome!';
var encode = xor.encode(plain);
var decode = xor.decode(encode);

print('>>> plain: $plain, encode: $encode, decode: $decode');
print('>>> decryption result is correct: ${plain == decode}'); // true
}
copied to clipboard
2. without a secret key
import 'dart:convert';
import 'package:xor_dart/xor_dart.dart';

void main() {
var content = '1234567890';
var bytes = utf8.encode(content);

// To bytes
var en = CipherXor.encrypt(bytes);
var de = CipherXor.decrypt(en);
print('content: $bytes, encrypted: $en, decrypted: $de');

// To strings
var encrypted = CipherXor.encryptToBase64(content);
var decrypted = CipherXor.decryptFromBase64(encrypted);
print('content: $content, encrypted: $encrypted, decrypted: $decrypted');
print('>>>>>>>> decryption result is correct:: ${content == decrypted}'); // true
}
copied to clipboard
3. XOR encrypt/decrypt a file
import 'dart:io';
import 'package:xor_dart/xor_dart.dart';

// i.e:
// dart ~/xor.dart/example/main.dart -en nohup.zip nohup.zip.en
// dart ~/xor.dart/example/main.dart -de nohup.zip.en nohup.out.zip
void main(List<String> args) {
print('args: $args');
var action = args.first.toLowerCase();

/// XOR encrypt a file
if (action.contains('-en')) {
File(args[2]).writeAsBytesSync(CipherXor.encrypt(File(args[1]).readAsBytesSync()));
}

/// XOR decrypt a file
if (action.contains('-de')) {
File(args[2]).writeAsBytesSync(CipherXor.decrypt(File(args[1]).readAsBytesSync()));
}
}
copied to clipboard
License #
MIT
Features and bugs #
Please feel free to:
request new features and bugs at the issue tracker

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.