static DHPublicKey parseDH(DataByteInputStream in) throws IOException { int special = 0; int pLength = in.readUnsignedShort(); if (pLength < 16 && pLength != 1 && pLength != 2) return null; BigInteger p; if (pLength == 1 || pLength == 2) { if (pLength == 1) special = in.readUnsignedByte(); else special = in.readUnsignedShort(); if (special != 1 && special != 2) return null; if (special == 1) p = DHPRIME768; else p = DHPRIME1024; } else p = in.readBigInteger(pLength); int gLength = in.readUnsignedShort(); BigInteger g; if (gLength == 0) { if (special != 0) g = TWO; else return null; } else g = in.readBigInteger(gLength); int yLength = in.readUnsignedShort(); BigInteger y = in.readBigInteger(yLength); return new DHPubKey(p, g, y); }
static RSAPublicKey parseRSA(DataByteInputStream in) throws IOException { int exponentLength = in.readUnsignedByte(); if (exponentLength == 0) exponentLength = in.readUnsignedShort(); BigInteger exponent = in.readBigInteger(exponentLength); int modulusLength = in.available(); BigInteger modulus = in.readBigInteger(modulusLength); RSAPublicKey rsa = new RSAPubKey(modulus, exponent); return rsa; }