Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private int e;
- private BigInteger n;
- private BigInteger d;
- private BigInteger p;
- private BigInteger q;
- private BigInteger dmp1;
- private BigInteger dmq1;
- private BigInteger coeff;
- private RSA(final BigInteger n, final int e, final BigInteger d, final BigInteger p, final BigInteger q, final BigInteger dmp1, final BigInteger dmq1, final BigInteger coeff){
- this.n = n;
- this.e = e;
- this.d = d;
- this.p = p;
- this.q = q;
- this.dmp1 = dmp1;
- this.dmq1 = dmq1;
- this.coeff = coeff;
- }
- private int GetBlockSize() {
- return ((this.n.bitCount() + 7) / 8);
- }
- private byte[] pkcs1unpad(final BigInteger _arg1, final int _arg2) {
- byte[] bytes = _arg1.toByteArray();
- int i = 0;
- while (i < bytes.length && bytes[i] == 0) ++i;
- if (bytes.length - i != (_arg2 - 1) || bytes[i] != 0x2)
- {
- return null;
- }
- i++;
- while(bytes[i] != 0) {
- ++i;
- if(i >= bytes.length) {
- return null;
- }
- }
- byte[] result = new byte[bytes.length - i + 1];
- int p = 0;
- while(++i < bytes.length) {
- result[p++] = bytes[i];
- }
- return result;
- }
- public BigInteger doPrivate2(final BigInteger k) {
- return k.modPow(this.d, this.n);
- }
- public byte[] Decript(String Key) {
- BigInteger m = new BigInteger(Key, 16);
- BigInteger c = this.doPrivate2(m);
- if (c.bitLength() == 0)
- {
- return null;
- }
- byte[] bytes = this.pkcs1unpad(c, this.GetBlockSize());
- if (bytes.length == 0)
- {
- return null;
- }
- return bytes;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement