Example usage for org.bouncycastle.crypto.params X25519PrivateKeyParameters getEncoded

List of usage examples for org.bouncycastle.crypto.params X25519PrivateKeyParameters getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.params X25519PrivateKeyParameters getEncoded.

Prototype

public byte[] getEncoded() 

Source Link

Usage

From source file:com.distrimind.util.crypto.ASymmetricEncryptionType.java

License:Open Source License

@SuppressWarnings("deprecation")
static byte[] encodePrivateKey(PrivateKey key, ASymmetricAuthenticatedSignatureType type, boolean xdh) {
    if (type == ASymmetricAuthenticatedSignatureType.BC_SHA384withECDSA_CURVE_25519
            || type == ASymmetricAuthenticatedSignatureType.BC_SHA512withECDSA_CURVE_25519
            || type == ASymmetricAuthenticatedSignatureType.BC_SHA256withECDSA_CURVE_25519) {
        return ((ECPrivateKey) key).getD().toByteArray();
    } else if (type == ASymmetricAuthenticatedSignatureType.BC_Ed25519) {
        if (xdh) {
            X25519PrivateKeyParameters k = null;
            try {
                k = (X25519PrivateKeyParameters) xdhPrivateKeyField.get(key);
            } catch (IllegalAccessException e) {
                e.printStackTrace();/*from w ww.j  av  a2  s.c om*/
                System.exit(-1);
            }
            return k.getEncoded();
        } else {

            Ed25519PrivateKeyParameters k = null;
            try {
                k = (Ed25519PrivateKeyParameters) eddsaPrivateKeyField.get(key);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                System.exit(-1);
            }
            return k.getEncoded();
        }
    } else if (type == ASymmetricAuthenticatedSignatureType.BC_Ed448) {
        if (xdh) {
            X448PrivateKeyParameters k = null;
            try {
                k = (X448PrivateKeyParameters) xdhPrivateKeyField.get(key);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                System.exit(-1);
            }
            return k.getEncoded();
        } else {
            Ed448PrivateKeyParameters k = null;
            try {
                k = (Ed448PrivateKeyParameters) eddsaPrivateKeyField.get(key);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                System.exit(-1);
            }
            return k.getEncoded();
        }
    } else
        return key.getEncoded();
    //return Bits.concateEncodingWithShortSizedTabs(key.getAlgorithm().encode(), key.getEncoded());
}