Skip to content

Instantly share code, notes, and snippets.

@LeetCodes
Forked from Mayeu/keybatch.sh
Created November 12, 2021 02:22
Show Gist options
  • Save LeetCodes/2ac89bffea489d70a7c24278c9f4d7d6 to your computer and use it in GitHub Desktop.
Save LeetCodes/2ac89bffea489d70a7c24278c9f4d7d6 to your computer and use it in GitHub Desktop.

Revisions

  1. @Mayeu Mayeu created this gist Jan 23, 2014.
    14 changes: 14 additions & 0 deletions keybatch.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    gpg --gen-key --batch <<EOF
    Key-Type: RSA
    Key-Length: 4096
    Subkey-Type: RSA
    Subkey-Length: 4096
    Name-Real: <ton_nom>
    Name-Email: <ton_mail>
    Expire-Date: 0
    Passphrase: <ta_passphrase>
    %pubring foo${1}.pub
    %secring foo${1}.sec
    # Do a commit here, so that we can later print "done" :-)
    %commit
    EOF
    42 changes: 42 additions & 0 deletions keygen.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #! /usr/bin/env perl

    use strict;
    use warnings;

    my $stop = 0;

    # Get the "thread" number
    my $number = shift @ARGV;

    my $KEYRING_OPTS = "--no-default-keyring --secret-keyring ./foo$number.sec --keyring ./foo$number.pub" ;

    until ($stop) {

    # Generate a key
    `bash keybatchgen.sh $number`;

    # Get the key short ID
    my $short_id = `gpg $KEYRING_OPTS --list-secret-keys | grep 'sec ' | cut -d ' ' -f 4`;

    # Cut the 4096R part
    $short_id =~ s/4096R\///;
    chomp $short_id;

    # Print it
    #print $short_id ;

    # Only export if it match a pattern
    if ( $short_id =~
    m/(FACE|C0FFEE|BAD|F00D|1CE|B00DDA|B00DA|CAFE|D00D|FEED|DEAD|BEAF|BEEF|C0DE|B00C|DEFACED|B00B|1DEA|DEFECA7E|D06|A55|CA7|CACA|B002E|B0A|B16|BABE|DAD|B10|B0D1|FA7|DEAF)/o
    )
    {
    print "Export $short_id\n";

    # Create the filename
    my $base_name = '0x' . $short_id;

    # export it
    `gpg $KEYRING_OPTS --output $base_name.pub.gpg --armor --export $short_id`;
    `gpg $KEYRING_OPTS --output $base_name.sec.gpg --armor --export-secret-key $short_id`;
    }
    }