Skip to content

Instantly share code, notes, and snippets.

View deiu's full-sized avatar

Andrei deiu

View GitHub Profile
@deiu
deiu / local-ip-check
Last active December 6, 2017 09:44
ES6 regex function to check if an origin (URL) is on the local network
/**
* Check if an (origin) URL is local based on the RFC 1918 list of reserved
* addresses. It accepts http(s) and ws(s) schemas as well as port numbers.
*
* localhost
* 127.0.0.0 – 127.255.255.255
* 10.0.0.0 – 10.255.255.255
* 172.16.0.0 – 172.31.255.255
* 192.168.0.0 – 192.168.255.255
* + extra zero config range on IEEE 802 networks:
Verifying my Blockstack ID is secured with the address 1JrhP8a5KrSmS7uCreg4JVaR7R7Qn7nFqG https://explorer.blockstack.org/address/1JrhP8a5KrSmS7uCreg4JVaR7R7Qn7nFqG
did:muport:QmPoZWgtvv8NQAkmfz6vBCrGQqb2nuBJgcrVLDb4Gqyz2e
@deiu
deiu / PBKDF2_to_AES.dart
Last active February 13, 2020 15:50
Generate AES key using PBDKF2 password derivation
import 'package:steel_crypt/steel_crypt.dart';
import 'dart:convert';
void main() async {
final passHash = PassCrypt('SHA-256/HMAC/PBKDF2');
final ivsalt = CryptKey().genDart(16);
final derivationPassword = 'foobar';
final derivedHash = passHash.hashPass(ivsalt, derivationPassword);
// prepare the key to be used by AesCrypt
final derivedBytes = base64Decode(derivedHash);