*/
public static void writeRSAKeyInfo(SimpleASNWriter asn, RSAKeyInfo keyInfo) {
// Write to a substream temporarily.
// This code needs to know the length of the substream before it can write the data from
// the substream to the main stream.
SimpleASNWriter asn2 = new SimpleASNWriter();
asn2.writeByte(0x02); // INTEGER (version)
byte[] version = new byte[1];
asn2.writeData(version);
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getModulus().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPublicExponent().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPrivateExponent().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPrimeP().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPrimeQ().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPrimeExponentP().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getPrimeExponentQ().toByteArray());
asn2.writeByte(0x02); // INTEGER ()
asn2.writeData(keyInfo.getCrtCoefficient().toByteArray());
byte[] rsaKeyEncoded = asn2.toByteArray();
asn.writeByte(0x30); // SEQUENCE
asn.writeData(rsaKeyEncoded);
}