package edu.iup.barrick.crypto; import java.math.BigInteger; /** * Implementation of basic RSA Encryption/Descryption Algorithm * @author Matthew J. Barrick */ public class RSA { /** * Constructor is declared as private, since this class holds only * static methods, and should never be instantiated */ private RSA() { } // STATIC FIELDS /////////////////////////////////////////////////////////////// /** * Generate Key pair for RSA Algorithm * @param p Prime p for RSA Key Generation * @param q Prime q for RSA Key Generation * @param e Choosen e for RSA Key Generation * @return Array containing RSA Key {Public Key, Private Key, n} */ static public BigInteger[] generateKey(BigInteger p, BigInteger q, BigInteger e) { BigInteger[] result = new BigInteger[3]; BigInteger phi = p.subtract(BigInteger.ONE) .multiply(q.subtract(BigInteger.ONE)); result[0] = e; result[1] = e.modInverse(phi); result[2] = p.multiply(q); return result; } }