Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.UnsupportedEncodingException;
- import java.math.BigInteger;
- public class BlindSignatureRSA {
- /*
- A - ALICE
- B - BOB
- e - открытый ключ
- d - закрытый ключ
- R - случайное число
- М - сообщение
- B --> A M' = M * R^e
- A --> B S' = ( M * R^e)^d = M^d * R^ed = M^d * R
- B: S'/R = (M^d * R)/R = M^d
- */
- public static BigInteger blindHideMsg(BigInteger M, BigInteger R, BigInteger e, BigInteger n) {
- // M' = M * R^e
- BigInteger hideMsg = M.multiply(R.modPow(e, n)).mod(n);
- return hideMsg;
- }
- public static BigInteger blindSignature(BigInteger blindMsg, BigInteger d, BigInteger n) {
- // S' = ( M * R^e)^d = M^d * R^ed = M^d * R
- BigInteger blindSig = blindMsg.modPow(d, n);
- return blindSig;
- }
- public static BigInteger blindRetrieveSig(BigInteger blindSig, BigInteger R, BigInteger n) {
- // S'/R = (M^d * R)/R = M^d
- BigInteger signature = blindSig.multiply(R.modInverse(n)).mod(n);
- return signature;
- }
- public static BigInteger stringToBigInteger(String str){
- byte [] raw = new byte[0];
- try {
- raw = str.getBytes("UTF8");
- } catch (UnsupportedEncodingException unsupportedEncodingException) {
- unsupportedEncodingException.printStackTrace();
- }
- return new BigInteger(raw);
- }
- public static void main(String[] args) {
- BigInteger e = new BigInteger("65537"); // открытый ключ
- BigInteger d = new BigInteger("60530511629930072241945671200867889027539295362393257858025617298274206834041"); // закрытый
- BigInteger n = new BigInteger("99418278299100976004220175767913358809660152882550697543248103911741071816073"); //mod n
- BigInteger R = new BigInteger("10879736607308378083"); //случайное число
- String message = "i love FCS"; // сообщение
- BigInteger M = stringToBigInteger(message); // форматируем нашу строку в BigInteger
- BigInteger blindMsg = blindHideMsg(M, R, e, n); // получаем M'
- BigInteger blindSig = blindSignature(blindMsg, d, n); // получаем S'
- BigInteger sig = blindRetrieveSig(blindSig, R, n); // получаем S'/R
- BigInteger realSig = M.modPow(d, n); // реальная подпись (sig = realSig)
- System.out.println("Message = " + M);
- System.out.println("Blind hide message = " + blindMsg);
- System.out.println("Blind signature = " + blindSig);
- System.out.println("Blind retrieve signature = " + sig);
- System.out.println("Signature = " + realSig);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement