@Override
    public void toPB(EncryptionKeyPB pb, KeyMgr mgr) {
        super.toPB(pb, mgr);
        pb.type = EncryptionKeyTypePB.NORMAL_KEY;
        pb.algorithm = algorithm;
        if (encryptedKey == null && plainKey != null) {
            // it's a plain master key
            pb.plainKey = plainKey;
        } else {
            pb.encryptedKey = encryptedKey;
        }
    }
@Test
    public void testToPB() {
        EncryptionKeyPB pb = new EncryptionKeyPB();
        KeyMgr mgr = new KeyMgr();
        normalKey.toPB(pb, mgr);

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