@Override
    public void fromPB(EncryptionKeyPB pb, KeyMgr mgr) {
        super.fromPB(pb, mgr);
        if (pb.algorithm == null) {
            throw new IllegalArgumentException("no algorithm in EncryptionKeyPB for NormalKey id:" + id);
        }
        algorithm = pb.algorithm;
        if (pb.plainKey != null) {
            plainKey = pb.plainKey;
        } else if (pb.encryptedKey != null) {
            encryptedKey = pb.encryptedKey;
        } else {
            throw new IllegalArgumentException("no encryptedKey in EncryptionKeyPB for NormalKey id:" + id);
        }
    }
@Test
    public void testFromPB() {
        EncryptionKeyPB pb = new EncryptionKeyPB();
        pb.id = 12345L;
        pb.createTime = System.currentTimeMillis();
        pb.algorithm = EncryptionAlgorithmPB.AES_128;
        pb.encryptedKey = ((NormalKey) normalKey.generateKey()).getEncryptedKey();

        NormalKey key = new NormalKey();
        KeyMgr mgr = new KeyMgr();
        key.fromPB(pb, mgr);

        assertEquals(pb.id.longValue(), key.getId());
        assertEquals(pb.createTime.longValue(), key.getCreateTime());
        assertEquals(pb.algorithm, key.getAlgorithm());
        assertArrayEquals(pb.encryptedKey, key.getEncryptedKey());
    }