Search in sources :

Example 1 with EncryptionError

use of com.icodici.crypto.EncryptionError in project universa by UniversaBlockchain.

the class KeyRecord method setupKey.

private void setupKey() {
    try {
        Object x = getOrThrow("key");
        remove("key");
        if (x instanceof PublicKey) {
            publicKey = (PublicKey) x;
        } else if (x instanceof PrivateKey) {
            publicKey = ((PrivateKey) x).getPublicKey();
        } else if (x instanceof String) {
            publicKey = new PublicKey(Base64u.decodeCompactString((String) x));
        } else {
            if (x instanceof Bytes)
                x = ((Bytes) x).toArray();
            if (x instanceof byte[]) {
                publicKey = new PublicKey((byte[]) x);
            } else {
                throw new IllegalArgumentException("unsupported key object: " + x.getClass().getName());
            }
        }
        put("key", publicKey);
    } catch (EncryptionError e) {
        throw new IllegalArgumentException("unsupported key, failed to construct", e);
    }
}
Also used : Bytes(net.sergeych.utils.Bytes) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) EncryptionError(com.icodici.crypto.EncryptionError)

Aggregations

EncryptionError (com.icodici.crypto.EncryptionError)1 PrivateKey (com.icodici.crypto.PrivateKey)1 PublicKey (com.icodici.crypto.PublicKey)1 Bytes (net.sergeych.utils.Bytes)1