private BigInteger n, d, e , p , q;
private BigInteger phi;
private int bitlength = 260;
private int bitlen = 256;
/** Create an instance that can encrypt using someone elses public key. */
public RSAA(BigInteger newn, BigInteger newe) {
n = newn;
e = newe;
}
public RSAA(int bits) {
/* bitlen = bits;
SecureRandom r = new SecureRandom();
BigInteger p = new BigInteger(bitlen / 2, 100, r);
BigInteger q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q
.subtract(BigInteger.ONE));
e = new BigInteger("3");
while (m.gcd(e).intValue() > 1) {
e = e.add(new BigInteger("2"));
}
d = e.modInverse(m);*/
Random r = new Random();
p = BigInteger.probablePrime(bitlength, r);
q = BigInteger.probablePrime(bitlength, r);
n = p.multiply(q);
phi = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e = BigInteger.probablePrime(bitlength/2, r);
while (phi.gcd(e).compareTo(BigInteger.ONE) > 0 && e.compareTo(phi) < 0 ) {
e.add(BigInteger.ONE);
}
d = e.modInverse(phi);
}
/** Encrypt the given plaintext message. */
public synchronized String encrypt(String message , BigInteger E) {
return (new BigInteger(message.getBytes())).modPow(E, n).toString();
}
/** Encrypt the given plaintext message. */
public synchronized BigInteger encrypt(BigInteger message , BigInteger E , BigInteger N ) {
return message.modPow(E, N);
}
/** Decrypt the given ciphertext message. */
public synchronized String decrypt(String message , BigInteger D) {
return new String((new BigInteger(message)).modPow(D, n).toByteArray());
}
/** Decrypt the given ciphertext message. */
public synchronized BigInteger decrypt(BigInteger message , BigInteger D , BigInteger N) {
return message.modPow(D, N);
}
/** Generate a new public and private key set. */
@SuppressLint("TrulyRandom")
public synchronized void generateKeys() {
SecureRandom r = new SecureRandom();
BigInteger p = new BigInteger(bitlen / 2, 100, r);
BigInteger q = new BigInteger(bitlen / 2, 100, r);
n = p.multiply(q);
BigInteger m = (p.subtract(BigInteger.ONE)).multiply(q
.subtract(BigInteger.ONE));
e = new BigInteger("3");
while (m.gcd(e).intValue() > 1) {
e = e.add(new BigInteger("2"));
}
d = e.modInverse(m);
}
/** Return the modulus. */
public synchronized BigInteger getN() {
return n;
}
/** Return the public key. */
public synchronized BigInteger getE() {
return e;
}
public synchronized BigInteger getD() {
return d;
}
public synchronized BigInteger getPPPP() {
return p;
}
public synchronized BigInteger getQQQQ() {
return q;
}
}
yang ingin saya tanyakan :
1. Kita tau dari mananya kalau itu emang script algoritma RSA
2. terus algoritma RSA diatas itu bitnya yg dipakai 256bit atau brp ?
3. Dan maksud bit yang dipakai itu untuk bagian apanya ? untuk kuncinya kah untuk bilangan primanya kah atau yang lain ?
4. yang paling membedakan algoritma Kriptografi RSA sama Kriptografi yang lainnya itu apanya ?
satu lagi ga, kalo ada referensi lengkap tentang algoritma RSA boleh saya minta.