Skip to content

Instantly share code, notes, and snippets.

@Spaider
Spaider / envelope_encryption_kms_boto_pycrypto.md
Last active December 12, 2023 23:59 — forked from pmp/envelope_encryption_kms_boto_pycrypto.md
Envelope Encryption using AWS KMS, Python Boto, and PyCrypto.

If you use Amazon AWS for nearly anything, then you are probably familiar with KMS, the Amazon Key Management Service.

KMS is a service which allows API-level access to cryptographic primitives without the expense and complexity of a full-fledged HSM or CloudHSM implementation. There are trade-offs in that the key material does reside on servers rather than tamper-proof devices, but these risks should be acceptable to a wide range of customers based on the care Amazon has put into the product. You should perform your own diligence on whether KMS is appropriate for your environment. If the security profile is not adequate, you should consider a stronger product such as CloudHSM or managing your own HSM solutions.

The goal here is to provide some introductory code on how to perform envelope encrypt a message using the AWS KMS API.

KMS allows you to encrypt messages of up to 4kb in size directly using the encrypt()/decrypt() API. To exceed these limitations, you must use a technique called "envelope encryptio

@Spaider
Spaider / KG_DailyProgress.user.js
Created December 10, 2017 20:13
Клавогонки: Визуальная полоса прогресса выполнения Задачи Дня.
// ==UserScript==
// @name Daily task progress bar
// @namespace klavogonki
// @version 0.1
// @description Add tiny progress bar to daily task badge
// @author Spaider aka Denis Dmitriev
// @match http://klavogonki.ru/*
// @grant none
// @iconr http://www.gravatar.com/avatar/f2cefb694c412538c4061eb822ae0528?s=48
// ==/UserScript==
@Spaider
Spaider / UpdateProfileEmail.sql
Created May 17, 2013 14:19
Updates membership email from email in racer details.
Declare @oldEmail Varchar(100) = '<specify old email here>'
Declare @newEmail Varchar(100)
Declare @racerID Int
Declare @userId Uniqueidentifier
Set @userId = (Select am.UserId From aspnet_Membership am Where am.Email Like @oldEmail)
Print 'User ID: ' + Cast(@userId As Varchar(45))
Set @racerID = (
@Spaider
Spaider / DataAccessSample-01.cs
Created February 22, 2013 09:04
Shows how to work with DB instances in custom data accessors.
/// <summary>
/// Accessor for working with Stuff
/// </summary>
public static class SampleDataAccessor
{
/// <summary>
/// This overload opens DB connection and thus, manages DB state.
/// Wrapping creation in using clause ensures that it will be
/// properly disposed
/// </summary>
@Spaider
Spaider / klavogonki-ru.user.js
Last active December 13, 2015 16:48
Auto-start open races on Klavogonki.ru
// ==UserScript==
// @name KlavogonkiAutoStart
// @namespace klavogonki.ru
// @version 0.0.2.0
// @description Auto start open races on Klavogonki.Ru site
// @author Spaider
// @grant none
// @include http://klavogonki.ru/*
// ==/UserScript==
@Spaider
Spaider / .eslintrc
Created December 9, 2015 08:38
ESLint configuration for Athlinks project
{
"rules": {
"indent": [2, 2, {"SwitchCase" : 1, "VariableDeclarator" : 2}],
"quotes": [2, "single"],
"linebreak-style": [0, "unix"],
"semi": [2, "always"],
"camelcase": 2,
"no-underscore-dangle": 2,
"no-console": 1, // Allow console for debug purposes. Must be configured as error for production
"semi-spacing": 2,
@Spaider
Spaider / TimePicker.jsx
Created November 19, 2015 15:16
Event time picker component (12 hours format only; 15 minutes granularity)
var React = require('react'),
Select = require('../../Shared/Form/Select.jsx'),
_ = require('lodash');
var TimePicker = React.createClass({
propTypes: {
hh: React.PropTypes.number.isRequired,
mm: React.PropTypes.number.isRequired,
onChange: React.PropTypes.func
with db_file_cte as
(
select
name,
type_desc,
physical_name,
size_mb =
convert(decimal(11, 2), size * 8.0 / 1024),
space_used_mb =
convert(decimal(11, 2), fileproperty(name, 'spaceused') * 8.0 / 1024)
@Spaider
Spaider / DB tables physical size.sql
Created October 9, 2015 12:30
Shows physical size for files related to database tables
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
SELECT
sysobjects.name AS trigger_name
,USER_NAME(sysobjects.uid) AS trigger_owner
,s.name AS table_schema
,OBJECT_NAME(parent_obj) AS table_name
,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate
,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete
,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert
,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter
,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof