Skip to content

Instantly share code, notes, and snippets.

@maxpowel
maxpowel / typescript_aes.ts
Created October 25, 2022 12:07
AES using typescript
import { cipher, util } from "node-forge";
# npm i --save-dev @types/node-forge
const secretKey = "12a97d88d634afdf9f4da5bd35223f01";
const iv = "5bf11a0951fa";
# Doing encryption
const cipherGCM = cipher.createCipher("AES-GCM", this.secretKey);
cipherGCM.start({iv: this.iv});
cipherGCM.update(util.createBuffer("Test message"))
@maxpowel
maxpowel / mongod.conf
Last active October 25, 2022 11:59
Secure mongo server
security:
authorization: "enabled"
@maxpowel
maxpowel / rust_ring_aes.rs
Created October 25, 2022 11:50
Example of encrypt and decrypt AES using ring ilbrary
/// Deps:
/// ring = "0.16.20"
/// base64 = "0.13.1"
/// Rust version 1.64.0
use ring::aead::{AES_256_GCM, UnboundKey};
use base64::{encode, decode};
use ring::{aead, error, rand};
struct OneNonceSequence(Option<aead::Nonce>);
@maxpowel
maxpowel / test_redis_lock.py
Created November 5, 2019 15:59
Distributed lock using redis
from redis import Redis, exceptions
import time
from uuid import uuid4
class DistributedLock(object):
def __init__(self, redis_client, lock_name, owner_id=None, lock_ttl=10, poll_time=1):
"""
:param redis_client: The redis client, can be strict or normal
@maxpowel
maxpowel / crypto.py
Created December 18, 2017 17:33
Python AES Cipher
import base64
import hashlib
from Crypto import Random
from Crypto.Cipher import AES
class AESCipher(object):
def __init__(self, key):
self.key = hashlib.sha256(key.encode()).digest()
@maxpowel
maxpowel / AESCipher.java
Created December 18, 2017 17:30
Java AES Cipher
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
import java.security.SecureRandom;
import java.security.MessageDigest;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
@maxpowel
maxpowel / create.sql
Created September 27, 2017 09:56
Create and grant permissions in Mysql
CREATE DATABASE testdb
GRANT ALL PRIVILEGES ON testdb.* To 'testuser'@'%' IDENTIFIED BY 'plainPassword';