English 中文(简体)
如何在 Java实施RSA加密和加密
原标题:How to implement RSA encrypt and decrypt in Java
  • 时间:2011-01-01 02:02:22
  •  标签:
  • java
  • rsa

我有公共和私人的关键一代。 我的下一步是创造另外2种方法——加密和加密。 我不敢肯定如何实施加密和加密。 我有几种想法,但似乎没有好的解决办法。 任何见解?

public class RSA
{
    private final static BigInteger one = new BigInteger("1");
    private final static SecureRandom random = new SecureRandom();

    // prime numbers
    private BigInteger p;
    private BigInteger q;

    // modulus
    private BigInteger n;

    // totient
    private BigInteger t;

    // public key
    private BigInteger e;

    // private key
    private BigInteger d;

    /**
     * Constructor for objects of class RSA
     */
    public RSA(int N)
    {
        p = BigInteger.probablePrime(N/2, random);
        q = BigInteger.probablePrime(N/2, random);

        // initialising modulus
        n = p.multiply(q);

        // initialising t by euclid s totient function (p-1)(q-1)
        t = (p.subtract(one)).multiply(q.subtract(one));

        // initialising public key ~ 65537 is common public key
        e = new BigInteger("65537");
    }

    public int generatePrivateKey()
    {
         d = e.modInverse(t);
         return d.intValue();
    }
}
问题回答

由于你真的要问一个具体问题,我恳请你作出一些实质性的答复。

DIY 著名的是像DIY核电这样的一条轨道。

I recommend reading bouncy castle if you want to learn about crypto coding, and using it rather than rolling your own.

如果你的模块是/em> 比照广,你的公用钥匙也将是n比照广。 一个简单的<代码>int赢得了t work。

See also

My own humble attempt at RSA encryption in Java:
http://david.tribble.com/src/java/tribble/crypto/RSACipher.java





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签