Open choiseonghyuk opened 7 years ago
여기 에디터는 Markdown의 문법을 따릅니다!
코드를 작성하실 때 ₩₩₩ <- 이거 세개로 시작해서
₩₩₩< - 세개로 끝내주시면 코드가 깔끔하게 나옵니다.
음.. 그리고 보통 이렇게 구현해보시는것도 좋은 경험이 될거라 생각하지만, 보통의 경우에는 모두 구현되어있습니다
http://www.java2s.com/Tutorial/Java/0490__Security/BasicRSAexample.htm
여기 참고해보세요~!
네그럼 저걸로 바꾸라는말씀이ㅛㅣㄴ가요
네에~!! 이걸 사용하셔도 되고, 다른 오픈소스가 있다면 그걸 사용하셔도 됩니다.
package dao;
import java.math.BigInteger; import java.util.Random;
public class PwprivateDao { int p,q,n,pi,e,d; BigInteger q1,q2,n1,p1,e1,d1,pi1; //랜덤함수로 소수구하기 및 반복 int returns(){ Random random=new Random(); int q=0; boolean c=true; boolean a = true; // for(int j=0; j<2; j++){ while(c) { int num=(int)(Math.random()999999999)+000000000; for(int i=2; i<num; i++){ if(num%i==0){ a=false; break; } } if (a) { c=false; q=num; }else{ a=true; continue; }
} // c=true; System.out.println(q); // } return q; } //값은값이면 다시출력 및 낮은숫자 앞으로 String result(int random,int random1){ boolean a=true; int q,k; while(a){ if(random!=random1){ a=false; }else{ random1=returns(); continue; } } if(random<random1){ q=random; k=random1; }else{ k=random; q=random1; } return q+" "+k; } int privatekey(int e,int pi){ int d=0; for(int i=0; i<pi; i++){ if(i!=0){ if((ie)%pi==1){ d=i; } } } return d; } BigInteger[] privat(BigInteger pri[]){ System.out.println("암호화 작업중 입니다"); for(int i=0; i<pri.length; i++){ pri[i]=pri[i].modPow(e1, n1); System.out.print(pri[i]+" "); } System.out.println(""); return pri; }
}
보시면 랜덤으로 값을 받아와서 e와d값만 저장할까요 아님 소수를 지정하는게 좋은가요