Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97870487
KeyGenerator.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Jan 7, 00:17
Size
2 KB
Mime Type
text/x-java
Expires
Thu, Jan 9, 00:17 (2 d)
Engine
blob
Format
Raw Data
Handle
23424849
Attached To
R3229 Genome Privacy - SHCS App
KeyGenerator.java
View Options
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package
crypto.paillier
;
import
java.math.BigInteger
;
import
java.util.Random
;
import
java.util.Vector
;
import
crypto.PrimeGenerator
;
/**
*
* @author raisaro
*/
public
class
KeyGenerator
{
private
BigInteger
x
;
private
BigInteger
p
;
private
BigInteger
q
;
private
BigInteger
n
;
private
BigInteger
nsqr
;
private
BigInteger
h
;
private
BigInteger
g
;
private
BigInteger
x1
;
private
BigInteger
x2
;
public
KeyGenerator
(){
PrimeGenerator
pg
=
new
PrimeGenerator
();
Vector
<
BigInteger
>
bigPrimes
=
pg
.
getBigPrimes
(
320
,
2
);
this
.
p
=
bigPrimes
.
elementAt
(
0
);
this
.
q
=
bigPrimes
.
elementAt
(
1
);
this
.
n
=
p
.
multiply
(
q
);
this
.
nsqr
=
n
.
multiply
(
n
);
}
/**
* Generates a couple of private and public keys.
*/
public
void
generateKeys
(){
generatePrivateKey
();
generatePublicKey
();
}
public
BigInteger
getG
()
{
return
g
;
}
public
BigInteger
getH
()
{
return
h
;
}
public
BigInteger
getN
()
{
return
n
;
}
public
BigInteger
getX
()
{
return
x
;
}
public
BigInteger
getX1
()
{
return
x1
;
}
public
BigInteger
getX2
()
{
return
x2
;
}
/**
* Generates a Private Key a random integer x € [1,n^2/2].
*/
private
void
generatePrivateKey
(){
Random
prng
=
new
Random
(
System
.
currentTimeMillis
()
);
long
rand
;
// rand = Math.abs( prng.nextLong() ) % (nsqr.divide(BigInteger.valueOf(2))).longValue();
// x = BigInteger.valueOf(rand);
x
=
new
BigInteger
(
2048
,
new
Random
());
x
=
x
.
mod
(
nsqr
.
divide
(
BigInteger
.
valueOf
(
2
)));
x
=
x
.
add
(
BigInteger
.
ONE
);
rand
=
Math
.
abs
(
prng
.
nextLong
()
)
%
x
.
longValue
();
x1
=
BigInteger
.
valueOf
(
rand
);
x2
=
x
.
subtract
(
x1
);
}
/**
* Generates a Public Key given a random integer a € Z*nsqr.
*/
private
void
generatePublicKey
(){
Random
prng
=
new
Random
(
System
.
currentTimeMillis
()
);
long
rand
;
rand
=
Math
.
abs
(
prng
.
nextLong
()
)
%
nsqr
.
longValue
();
BigInteger
a
=
BigInteger
.
valueOf
(
rand
);
g
=
a
.
modPow
(
BigInteger
.
valueOf
(
2
),
nsqr
);
h
=
g
.
modPow
(
x
,
nsqr
);
}
}
Event Timeline
Log In to Comment