@SuppressWarnings("unchecked") public <T extends PemBlockModel> T set(String key, Object value) { put(key, value); return (T) this; }
public static PemKey toKey(String key) throws ParseException { return new PemKey(new PemBlockModel().parse(key)); }
public static void prepareCipherOut(PemPub key, PemBlockModel out, String name, String stringEncoding) throws MException { out.set(PemBlock.METHOD, name); if (stringEncoding != null) out.set(PemBlock.STRING_ENCODING, stringEncoding); if (key.isProperty(PemBlock.IDENT)) out.set(PemBlock.PUB_ID, key.getString(PemBlock.IDENT)); if (key.isProperty(PemBlock.PRIV_ID)) out.set(PemBlock.PRIV_ID, key.getString(PemBlock.PRIV_ID)); out.set(PemBlock.CREATED, new Date()); }
public static void prepareSignOut(PemPriv key, PemBlockModel out, String name) { out.set(PemBlock.METHOD,name); if (key.isProperty(PemBlock.IDENT)) out.set(PemBlock.PRIV_ID, key.getProperty(PemBlock.IDENT)); if (key.isProperty(PemBlock.PUB_ID)) out.set(PemBlock.PUB_ID, key.getProperty(PemBlock.PUB_ID)); out.set(PemBlock.CREATED, new Date()); }
@Override public void foundPublicKey(PemBlock block) { String id = block.getString(PemBlock.IDENT, null); if (id == null) return; keys.put(id, block); }
@Override public PemPub getPublicKey(String pubId) { PemBlock key = keys.get(pubId); if (key == null) return null; return new PemKey( key ); }
public static PemBlock parse(String entry) throws ParseException { return new PemBlockModel().parse(entry); }
public PemBlock find(String name) { for (PemBlock block : this) { if (name.equals(block.getName())) { return block; } } return null; } public PemBlock find(String name, String filter ) throws MException {
public PemBlockModel(String name) { setName(name); }
@Override public String getMethod() throws MException { return getString(PemBlock.METHOD); }
public PemEntry(String entry) throws ParseException { this(PemUtil.parse(entry)); }
public static void prepareSymmetricCipherOut(PemPub key, PemBlockModel out, String name, String stringEncoding) throws MException { out.set(PemBlock.METHOD, name); out.set(PemBlock.SYMMETRIC, true); if (stringEncoding != null) out.set(PemBlock.STRING_ENCODING, stringEncoding); if (key.isProperty(PemBlock.IDENT)) out.set(PemBlock.KEY_ID, key.getString(PemBlock.IDENT)); out.set(PemBlock.CREATED, new Date()); }
@Override public String getPrivateIdForPublicKeyId(String pubId) throws CryptException { PemBlock pub = keys.get(pubId); if (pub == null) return null; return pub.getString(PemBlock.PRIV_ID, null); }
@Override public PemPriv getPrivateKey(String privId) throws MException { PemBlock key = keys.get(privId); if (key == null) return null; return new PemKey( key ); }
public static boolean isCipher(PemBlock block) { return PemBlock.BLOCK_CIPHER.equals(block.getName()); }