Skip to content

Instantly share code, notes, and snippets.

import 'dart:isolate';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:webcrypto/webcrypto.dart';
void main() {
runApp(const MyApp());
}
const x25519_key = await crypto.subtle.generateKey(
{ name: "X25519" },
true, // Extractable
["deriveKey", "deriveBits"]
);
// Export the keys
const privateKeyJwk = await crypto.subtle.exportKey("pkcs8", x25519_key.privateKey);
const publicKeyJwk = await crypto.subtle.exportKey("spki", x25519_key.publicKey);
import 'dart:convert';
import 'dart:typed_data';
import 'package:pem/pem.dart';
import 'package:test/test.dart';
import 'package:webcrypto/webcrypto.dart';
void main() {
group('RsaOaepPrivateKey Tests', () {
final modulusLength = 2048;
final publicExponent = BigInt.from(65537);
@HamdaanAliQuatil
HamdaanAliQuatil / sdhi.go
Last active June 26, 2024 05:13
Strong Diffie Hellman Inversion using Cloudflare's CIRCL library
package main
import (
"crypto/rand"
"crypto/sha256"
"fmt"
"github.com/cloudflare/circl/ecc/bls12381"
)
type KDF struct {
@HamdaanAliQuatil
HamdaanAliQuatil / flutter test --coverage
Last active June 19, 2024 02:21
dart test .\lib\src\testing\webcrypto\ecdh.dart
PS C:\Users\Hamdaan\Desktop\downloads\webcrypto.dart> flutter test --coverage
00:17 +1425: All tests passed!
@HamdaanAliQuatil
HamdaanAliQuatil / hmac.dart
Created May 5, 2024 13:07
Example code for webcrypto.hmac.dart
import 'package:webcrypto/webcrypto.dart';
import 'dart:convert';
Future<void> main() async {
// Generate a new key using SHA-256 and an optional length parameter.
final key = await HmacSecretKey.generateKey(Hash.sha256, length: 256);
// Sign the message.
final signature = await key.signBytes(utf8.encode('Hello World!'));
@HamdaanAliQuatil
HamdaanAliQuatil / kanidm-log-windows
Created March 14, 2024 06:35
kanidm-log-windows
PS E:\kanidm> cargo test
warning: unused variable: `path`
--> libs\file_permissions\src\windows.rs:21:22
|
21 | pub fn diagnose_path(path: &Path) -> Diagnosis {
| ^^^^ help: if this is intentional, prefix it with an underscore: `_path`
|
= note: `#[warn(unused_variables)]` on by default
warning: `kanidm_lib_file_permissions` (lib) generated 1 warning (run `cargo fix --lib -p kanidm_lib_file_permissions` to apply 1 suggestion)
@HamdaanAliQuatil
HamdaanAliQuatil / kanidm-log-wsl
Last active March 14, 2024 06:36
kanidm-log-wsl
root@LAPTOP-B88S065R:/mnt/c/Users/Hamdaan/Desktop/kanidm# cargo test
Updating git repository `https://github.com/kanidm/webauthn-rs.git`
Updating crates.io index
Updating git repository `https://github.com/dnaeon/rust-sshkeys.git`
Downloaded pin-project v1.1.4
Downloaded password-hash v0.5.0
Downloaded prokio v0.1.0
Downloaded overload v0.1.1
Downloaded asn1-rs-derive v0.1.0
Downloaded async-stream-impl v0.3.5
@HamdaanAliQuatil
HamdaanAliQuatil / aa.controller.ts
Created March 11, 2024 08:50
hmac-diffie-hellman-merkle
import { generateKeyPair, generateSharedSecret, generateHMAC, KeyPair } from '../utils/crypto.utils';
import axios from 'axios';
let sharedSecret: Buffer;
export async function sendAAPublicKey(): Promise<Buffer> {
try {
const response = await axios.get('http://localhost:3000/init');
const boostPublicKey: Buffer = Buffer.from(response.data.boostPublicKey, 'hex');
@HamdaanAliQuatil
HamdaanAliQuatil / app.js
Created January 2, 2024 23:59
Defending against SSRF attacks
const express = require("express");
const axios = require("axios");
const fs = require("fs").promises;
const path = require("path");
const app = express();
const port = 3000;
// Function to fetch private resource
const fetchPrivateResource = async () => {