Ejemplo n.º 1
0
        private static byte[] fromRSAPublicKey(RSAPublicKey key)
        {
            DNSOutput @out = new DNSOutput();

            Org.BouncyCastle.Crypto.Parameters.RsaKeyParameters kp = key.PublicKey;

            // BigInteger exponent = key.getPublicExponent();
            Org.BouncyCastle.Math.BigInteger exponent = kp.Exponent;

            // BigInteger modulus = key.getModulus();
            Org.BouncyCastle.Math.BigInteger modulus = kp.Modulus;


            int exponentLength = Helpers.BigIntegerLength(exponent);

            if (exponentLength < 256)
            {
                @out.writeU8(exponentLength);
            }
            else
            {
                @out.writeU8(0);
                @out.writeU16(exponentLength);
            }

            Helpers.writeBigInteger(@out, exponent);
            Helpers.writeBigInteger(@out, modulus);

            return(@out.toByteArray());
        }
Ejemplo n.º 2
0
        public static byte[] fromDSAPublicKey(DSAPublicKey key)
        {
            DNSOutput @out = new DNSOutput();

            Org.BouncyCastle.Crypto.Parameters.DsaPublicKeyParameters dp = key.PublicKey;


            // BigInteger q = key.getParams().getQ();
            Org.BouncyCastle.Math.BigInteger q = dp.Parameters.Q;
            // BigInteger p = key.getParams().getP();
            Org.BouncyCastle.Math.BigInteger p = dp.Parameters.P;
            // BigInteger g = key.getParams().getG();
            Org.BouncyCastle.Math.BigInteger g = dp.Parameters.G;
            // BigInteger y = key.getY();
            Org.BouncyCastle.Math.BigInteger y = dp.Y;


            int t = (p.ToByteArray().Length - 64) / 8;

            @out.writeU8(t);

            Helpers.writeBigInteger(@out, q);
            Helpers.writeBigInteger(@out, p);
            Helpers.writePaddedBigInteger(@out, g, 8 * t + 64);
            Helpers.writePaddedBigInteger(@out, y, 8 * t + 64);

            return(@out.toByteArray());
        }