java - Construct Public Key from Big Integers? -
i construct public key constructed using c# xml rsakeys, reconstruct using java, problem receive m & e key bytes values, , construct key i've use 2 bigintegers, how construct public key ?
edit: problem mod, exp byte arrays base64 decoded, m,n of public key...
byte[] mod = base64.decodebase64(modulus.getbytes()); byte[] exp = base64.decodebase64(exponent.getbytes()); int[] copymod = new int[mod.length]; (int x = 0; x < mod.length; x++) { copymod[x] = unsignedtobytes((byte) mod[x]); } int[] copyexp = new int[exp.length]; (int x = 0; x < exp.length; x++) { copyexp[x] = unsignedtobytes((byte) exp[x]); } string mod = arrays.tostring(copymod); string exp = arrays.tostring(copyexp); biginteger m = new biginteger(mod.getbytes()); biginteger e = new biginteger(exp.getbytes()); java.security.spec.rsapublickeyspec spec = new java.security.spec.rsapublickeyspec(m, e); keyfactory keyfactory = keyfactory.getinstance("rsa"); publickey publickey = keyfactory.generatepublic(spec);
you don't tell object type want. if want rsa public key, can (bouncycastle):
rsapublickey rsapubkey = new jcersapublickey( new rsakeyparameters(false, modulus, exponent));
see class definition.
Comments
Post a Comment