I want to encrypt an image with ECC, i tried using Bouncy Castle
but it cant encrypt each pixel alone,and i asked about it in another question here
in stackoverflow and the Answer was to implement ECC without B**C.
So i searched about ECC and found:
Elliptic curve cryptography consists of three distinct operations:
1_ key generation:
- we need a
point G
,also called as the generator point. - a large integer
nB
is kept as the Private Key. - and the point
PB = nB * G
is declared as public. -map the plaintext message to a point on the elliptic curve(for that i get each pixele and multiplying it with G).
2_ encryption:
the sender chooses a
random positive integer k
.then uses the public key PB to generate the cipher point Cm that consists of two points.
Cm = [{k G}, {Pm +(k PB)}]
.
3_ decryption:
C2 – nB * C1 = {Pm + (k * PB)}{nB * (k * G)}
= Pm + k*(nB * G)nB * (k * G)
= Pm
The problem is when mapping the pixel and encrypting it the result is a point,how to get the value of the encrypted pixel from it, so i can create the new image? i'm in the right way of implementing ECC??
public static void main(String[] args) {
try{
X9ECParameters x9 = NISTNamedCurves.getByName("P-224");
org.bouncycastle.math.ec.ECPoint g = x9.getG();
BigInteger n = x9.getN();
int nBitLength = n.bitLength();
BigInteger privatekey;
do{
Random rand = new Random();
privatekey = new BigInteger(nBitLength,rand);
}
while (privatekey.equals(ZERO) || (privatekey.compareTo(n) >= 0));
org.bouncycastle.math.ec.ECPoint publickey = g.multiply(privatekey);
BigInteger k;
Random randk = new Random();
k= new BigInteger(nBitLength,randk);
File bmpFile = new File("C:\\Users\\acer\\Desktop\\py\\6.bmp");
BufferedImage image = ImageIO.read(bmpFile);
int width = image.getWidth();
int height = image.getHeight();
BigInteger [][] pixels = new BigInteger [width][height];
for( int i = 0; i < width; i++ )
for( int j = 0; j < height; j++ )
pixels[i][j] = BigInteger.valueOf(image.getRGB( i, j ));
org.bouncycastle.math.ec.ECPoint mappedpixel,encryptedpixel;
for( int i = 0; i < width; i++ ){
for( int j = 0; j < height; j++ ){
mappedpixel= g.multiply(pixels[i][j]);
encryptedpixel=mappedpixel.add(publickey.multiply(k));
}
}
}
catch (IOException e){
System.out.println(e.getMessage());
}
}
the problem is in the last 'for' it map the pixel and encrypt it but don't know how to put the value of encryptedpixel in the pixel to create the new image.