public static CryptoKey read(InputStream i, DSAGroup g) throws IOException { return new DSAPrivateKey(Util.readMPI(i), g); }
} else if (args[0].equals("read")) { System.out.println("9"); System.out.println(readMPI(System.in)); System.out.println("1234567890123456789"); System.out.println(readMPI(System.in)); System.out.println("100200300400500600700800900"); System.out.println(readMPI(System.in)); } else if (args[0].equals("write-mpi")) { writeMPI(new BigInteger(args[1]), System.out); } else if (args[0].equals("read-mpi")) { System.err.println(readMPI(System.in)); } else if (args[0].equals("keygen")) { byte[] entropy = readMPI(System.in).toByteArray(); byte[] key = new byte[(args.length > 1 ? Integer.parseInt(args[1]) : 16)];
/** * Parses a DSA Group from a string, where p, q, and g are in unsigned * hex-strings, separated by a commas */ // see readFromField() below //public static DSAGroup parse(String grp) { // StringTokenizer str=new StringTokenizer(grp, ","); // BigInteger p,q,g; // p = new BigInteger(str.nextToken(), 16); // q = new BigInteger(str.nextToken(), 16); // g = new BigInteger(str.nextToken(), 16); // return new DSAGroup(p,q,g); //} public static CryptoKey read(InputStream i) throws IOException, CryptFormatException { BigInteger p, q, g; p = Util.readMPI(i); q = Util.readMPI(i); g = Util.readMPI(i); try { DSAGroup group = new DSAGroup(p, q, g); if(group.equals(Global.DSAgroupBigA)) return Global.DSAgroupBigA; else return group; } catch (IllegalArgumentException e) { throw (CryptFormatException)new CryptFormatException("Invalid group: "+e).initCause(e); } }
public DSAPublicKey(InputStream is) throws IOException, CryptFormatException { DSAGroup g = (DSAGroup) DSAGroup.read(is); if(g == Global.DSAgroupBigA) g = null; group = g; y = Util.readMPI(is); if(y.compareTo(getGroup().getP()) > 0) throw new IllegalArgumentException("y must be < p but y=" + y + " p=" + getGroup().getP()); }