Identity-based Encryption (IBE) is an alternative to PKI, and involves generating the encryption key from a piece of identity for the recipient. For example we could use the email address of the recipient to generate the key for a destination. [Article]
Identity-based Encryption (IBE) |
Theory
Identity-based Encryption (IBE) is an alternative to PKI, and involves generating the encryption key from a piece of identity for the recipitant. For example we could use the email address of the recipitant to generate the key for a destination.
For this we have some shared paramters with a trust center that both Bob and Alice trust. If Alice wants to send Bob an email, she takes the parameters from the trust center, and then uses Bob's email address to generate his public key:
When Bob receives the encrypted email, he contacts the trust center and the center generates the private key required to decrypt the email.
Fun article: here
Java code
If we run the code from [here]:
ID (sender): alice@home ID (recipient): bob@home Message: This is a test public key of Server is : 796676165 -------Encrypted message is: 0-9252-1087273-1312447-82-122-3548100-98-12-59119-67910932-25-11-55103103-3845-47-6697-65101-187580-104-27-492875-85-104-11121-771093311056-89-73-294536-30-699157-62-997344-48-151674-22123-11914-2879-2546-10-33-224123-61-81-39-9236-1996-100-7412673-6517-1241647-1166-80112-25-96-47-1-48-3656-10918-714-6310-222689-84353-3711-206691-108-40-16-1057124824-2826-106-5111-341948-19-9089469-15-121-114-117-102322879114102121-9120-122-4816104-20-69-23-84-126-3-43109-31-87-10324984429-58496-41-56-108-9771-87106-2-768910858662-11311636114832-65-49-9333-10-76105-98-31-50-62-101-5623769-12832-39-2311310312330-61126-13-80113-118-10974-12610475-9-101-11-9-73-2823472-12862-3110-74-37119110
We can then send this to Bob:
===Server=== ID (recipient): bob@home Private Key is: 15628359065003500172265760243728795041059990069333676123396960693268218841954675950062210903458215692737042390611205283900795810879153296373134264353314946063818136144007902998988330580615949529856111153881616812931106960930579689039539622829349628030759597537177833096137408641676448032231547761658712229433986636644335024833553888671358674312406666648119336786772269233044477232625147852843704038178315939488166878330633386007927381114388285151574070141457295826380002095840403146327622513427020228074163991463007728153543845959984250176040444915694105302602134347815716010148208228519210734506151915037112792005149 --------------------Decrypted message is: alice@home has sent you a message: This is a test
Coding
An outline of the code is:
package Client; import java.math.BigInteger; public class Client { public static void main(String args[]){ String message,id_sender="alice@home",temp,id_recipient="bob@home"; id_recipient = args[1]; id_sender = args[0]; message=args[2]; System.out.println("ID (sender): "+id_sender+","+" ID (recipient): "+id_recipient); System.out.println("Message: "+message); message = id_recipient+" has sent this message:\n"+message; byte[] m = message.getBytes(); PKG pkg = new PKG(); BigInteger Public_key = pkg.get_public_key(id_recipient); Public_key = pkg.get_public_key(id_sender); BigInteger n = pkg.getn(); System.out.println("Recipient Public Key: " + Public_key); System.out.println("\nEncrypted message:"); System.out.println(bytesToString((new BigInteger(m)).modPow(Public_key, n).toByteArray())); System.out.println("\n==== Server"); System.out.println("id_sender (recipient): "+id_recipient); BigInteger Private_key =pkg.get_private_key(id_sender); System.out.println("Private Key is: " + Private_key ); System.out.println("\nDecrypted message:"); byte [] enc = (new BigInteger(m)).modPow(Public_key, n).toByteArray(); byte [] dec = (new BigInteger(enc)).modPow(Private_key, n).toByteArray(); System.out.println(new String(dec)); } private static String bytesToString(byte[] encrypted) { String str = ""; for (byte b : encrypted) { str += Byte.toString(b); } return str; } }
We see the lines of:
byte [] enc = (new BigInteger(m)).modPow(Public_key, n).toByteArray(); byte [] dec = (new BigInteger(enc)).modPow(Private_key, n).toByteArray(); System.out.println(new String(dec));
We thus calculate the public key (Public_key) and the private key (Private_key), and then the encrypted cipher is:
\(Cipher = (Message)^{Public key} \mod N\)
and then we decrypt with:
\(Message = (Cipher)^{Private key} \mod N\)