Beispiel #1
0
        getEncoded()
        {
            // First encode an PKCS #1 RSAPublicKey.
            var rsaPublicKey = new DerNode.DerSequence();

            rsaPublicKey.addChild(new DerNode.DerInteger
                                      (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.Modulus)));
            rsaPublicKey.addChild(new DerNode.DerInteger
                                      (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.Exponent)));

            // Encode rsaPublicKey as an X.509 public key.
            var algorithmIdentifier = new DerNode.DerSequence();

            algorithmIdentifier.addChild(new DerNode.DerOid(new OID(RsaKeyFactory.RSA_ENCRYPTION_OID)));
            algorithmIdentifier.addChild(new DerNode.DerNull());

            var publicKey = new DerNode.DerSequence();

            publicKey.addChild(algorithmIdentifier);
            publicKey.addChild(new DerNode.DerBitString(rsaPublicKey.encode().buf(), 0));

            return(publicKey.encode().getImmutableArray());
        }
Beispiel #2
0
        getEncoded()
        {
            // First encode an PKCS #1 RSAPrivateKey.
            var rsaPrivateKey = new DerNode.DerSequence();

            rsaPrivateKey.addChild(new DerNode.DerInteger(0));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.Modulus)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.Exponent)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.D)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.P)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.Q)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.DP)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.DQ)));
            rsaPrivateKey.addChild(new DerNode.DerInteger
                                       (RsaKeyFactory.getPositiveIntegerBuffer(Parameters.InverseQ)));

            // Encode rsaPrivateKey as a PKCS #8 private key.
            var algorithmIdentifier = new DerNode.DerSequence();

            algorithmIdentifier.addChild(new DerNode.DerOid(new OID(RsaKeyFactory.RSA_ENCRYPTION_OID)));
            algorithmIdentifier.addChild(new DerNode.DerNull());

            var privateKey = new DerNode.DerSequence();

            privateKey.addChild(new DerNode.DerInteger(0));
            privateKey.addChild(algorithmIdentifier);
            privateKey.addChild(new DerNode.DerOctetString(rsaPrivateKey.encode().buf()));

            return(privateKey.encode().getImmutableArray());
        }