Example usage for org.bouncycastle.jcajce.provider.asymmetric.util KeyUtil getEncodedSubjectPublicKeyInfo

List of usage examples for org.bouncycastle.jcajce.provider.asymmetric.util KeyUtil getEncodedSubjectPublicKeyInfo

Introduction

In this page you can find the example usage for org.bouncycastle.jcajce.provider.asymmetric.util KeyUtil getEncodedSubjectPublicKeyInfo.

Prototype

public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData) 

Source Link

Usage

From source file:com.raphfrk.craftproxyclient.net.protocol.p16x.P16xProtocol.java

License:Open Source License

public byte[] encodeRSAPublicKey(RSAKeyParameters key) {
    if (((RSAKeyParameters) key).isPrivate()) {
        return null;
    }/*  w  w w .j a  v a 2  s.  co m*/

    RSAKeyParameters rsaKey = (RSAKeyParameters) key;

    ASN1EncodableVector encodable = new ASN1EncodableVector();
    encodable.add(new ASN1Integer(rsaKey.getModulus()));
    encodable.add(new ASN1Integer(rsaKey.getExponent()));

    return KeyUtil.getEncodedSubjectPublicKeyInfo(
            new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE),
            new DERSequence(encodable));
}

From source file:org.spout.api.security.SecurityHandler.java

License:Open Source License

public byte[] encodeKey(CipherParameters key) {
    if (!(key instanceof RSAKeyParameters)) {
        return null;
    }//from   ww  w .  j a  v  a  2 s.  c om

    if (((RSAKeyParameters) key).isPrivate()) {
        return null;
    }

    RSAKeyParameters rsaKey = (RSAKeyParameters) key;

    ASN1EncodableVector encodable = new ASN1EncodableVector();
    encodable.add(new ASN1Integer(rsaKey.getModulus()));
    encodable.add(new ASN1Integer(rsaKey.getExponent()));

    return KeyUtil.getEncodedSubjectPublicKeyInfo(
            new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()),
            new DERSequence(encodable));
}