Last active
August 29, 2015 14:14
-
-
Save badmofo/9730ec955996fd96cd90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Similar in spirit to https://github.com/arttukasvio/deterministic | |
// It's a really bad idea to use this unless you absolutely know what | |
// you are doing. | |
@Grab(group='org.bouncycastle', module='bcpg-jdk15on', version='1.51') | |
import java.security.*; | |
import org.bouncycastle.jce.provider.BouncyCastleProvider; | |
import org.bouncycastle.bcpg.ArmoredOutputStream; | |
import org.bouncycastle.bcpg.HashAlgorithmTags; | |
import org.bouncycastle.openpgp.*; | |
import org.bouncycastle.openpgp.operator.jcajce.*; | |
def size = 4096; | |
def identity = args[0]; | |
def passPhrase = args[1]; | |
def seed = passPhrase.getBytes("UTF-8"); | |
def outputArmored(obj) { | |
def armoredOut = new ArmoredOutputStream(System.out); | |
obj.encode(armoredOut); | |
armoredOut.close(); | |
} | |
Security.addProvider(new BouncyCastleProvider()); | |
prng = SecureRandom.getInstance("SHA1PRNG"); | |
prng.setSeed(seed) | |
kpg = KeyPairGenerator.getInstance("RSA", "BC"); | |
kpg.initialize(size, prng); | |
keyPair = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, kpg.generateKeyPair(), new Date(0)); | |
sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1); | |
secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, keyPair, identity, sha1Calc, null, null, | |
new JcaPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), | |
new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5, sha1Calc).setProvider("BC").build(passPhrase.toCharArray())); | |
outputArmored(secretKey); | |
outputArmored(secretKey.getPublicKey()); | |
println("KEYID: " + Long.toHexString(keyPair.getKeyID()).toUpperCase()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment