All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.libg.cryptography.RSA Maven / Gradle / Ivy

Go to download

A main program (executable JAR) that will listen to port 29998. At first, it can only answer that it is an Envoy (a limited agent). The only function it supports is installing a -runpath. It will then create a framework + agent and transfer the connection to the just installed agent who will then install the bundles. This JAR is a main command for JPM called bndremote. In JPM, it will start up with debug enabled. This JAR does some highly complicated class loading wizardy to ensure that it does not enforce any constraints on the -runpath.

The newest version!
package aQute.libg.cryptography;

import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;

import aQute.libg.tuple.Pair;

public class RSA {
	final static String		ALGORITHM	= "RSA";

	final static KeyFactory	factory		= getKeyFactory();

	static private KeyFactory getKeyFactory() {
		try {
			return KeyFactory.getInstance(ALGORITHM);
		} catch (Exception e) {
			// built in
		}
		return null;
	}

	public static RSAPrivateKey create(RSAPrivateKeySpec keyspec) throws InvalidKeySpecException {
		return (RSAPrivateKey) factory.generatePrivate(keyspec);
	}

	public static RSAPublicKey create(RSAPublicKeySpec keyspec) throws InvalidKeySpecException {
		return (RSAPublicKey) factory.generatePrivate(keyspec);
	}

	public static RSAPublicKey createPublic(BigInteger m, BigInteger e) throws InvalidKeySpecException {
		return create(new RSAPublicKeySpec(m, e));
	}

	public static RSAPrivateKey createPrivate(BigInteger m, BigInteger e) throws InvalidKeySpecException {
		return create(new RSAPrivateKeySpec(m, e));
	}

	public static Pair generate() throws NoSuchAlgorithmException {
		KeyPairGenerator kpg = KeyPairGenerator.getInstance(ALGORITHM);
		KeyPair keypair = kpg.generateKeyPair();
		return new Pair<>((RSAPrivateKey) keypair.getPrivate(), (RSAPublicKey) keypair.getPublic());
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy