public static CryptoKey read(InputStream i) throws IOException, CryptFormatException { return new DSAPublicKey(i); }
public DSAPublicKey cloneKey() { return new DSAPublicKey(this); }
public static DSAPublicKey create(byte[] pubkeyAsBytes) throws CryptFormatException { try { return new DSAPublicKey(new ByteArrayInputStream(pubkeyAsBytes)); } catch(IOException e) { throw new CryptFormatException(e); } }
public InsertableClientSSK getInsertableSSK(String string) { try { return new InsertableClientSSK(string, pubKeyHash, new DSAPublicKey(getCryptoGroup(), privKey), privKey, cryptoKey, cryptoAlgorithm); } catch (MalformedURLException e) { Logger.error(this, "Caught "+e+" should not be possible in USK.getSSK", e); throw new Error(e); } }
public static DSAPublicKey create(SimpleFieldSet set, DSAGroup group) throws FSParseException { BigInteger x; try { x = new BigInteger(1, Base64.decode(set.get("y"))); } catch (IllegalBase64Exception e) { throw new FSParseException(e); } try { return new DSAPublicKey(group, x); } catch (IllegalArgumentException e) { throw new FSParseException(e); } }
public static ClientKSK create(String keyword) { MessageDigest md256 = SHA256.getMessageDigest(); try { byte[] keywordHash; try { keywordHash = md256.digest(keyword.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e); } MersenneTwister mt = new MersenneTwister(keywordHash); DSAPrivateKey privKey = new DSAPrivateKey(Global.DSAgroupBigA, mt); DSAPublicKey pubKey = new DSAPublicKey(Global.DSAgroupBigA, privKey); byte[] pubKeyHash = md256.digest(pubKey.asBytes()); try { return new ClientKSK(keyword, pubKeyHash, pubKey, privKey, keywordHash); } catch (MalformedURLException e) { throw new Error(e); } } finally { SHA256.returnMessageDigest(md256); } }
public static InsertableClientSSK createRandom(RandomSource r, String docName) { byte[] ckey = new byte[CRYPTO_KEY_LENGTH]; r.nextBytes(ckey); DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, r); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); try { byte[] pkHash = SHA256.digest(pubKey.asBytes()); return new InsertableClientSSK(docName, pkHash, pubKey, privKey, ckey, Key.ALGO_AES_PCFB_256_SHA256); } catch (MalformedURLException e) { throw new Error(e); } }
throw new MalformedURLException("SSK private key (routing key) is invalid: " + e); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = pubKey.asBytesHash(); return new InsertableClientSSK(uri.getDocName(), pkHash, pubKey, privKey, uri.getCryptoKey(), keyType);
public static KeyBlock createBlock(short keyType, byte[] keyBytes, byte[] headersBytes, byte[] dataBytes, byte[] pubkeyBytes) throws KeyVerifyException { byte type = (byte)(keyType >> 8); byte subtype = (byte)(keyType & 0xFF); if(type == NodeCHK.BASE_TYPE) { // For CHKs, the subtype is the crypto algorithm. return CHKBlock.construct(dataBytes, headersBytes, subtype); } else if(type == NodeSSK.BASE_TYPE) { DSAPublicKey pubKey; try { pubKey = new DSAPublicKey(pubkeyBytes); } catch (IOException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } catch (CryptFormatException e) { throw new KeyVerifyException("Failed to construct pubkey: "+e, e); } NodeSSK key = new NodeSSK(pubKey.asBytesHash(), keyBytes, pubKey, subtype); return new SSKBlock(dataBytes, headersBytes, key, false); } else { throw new KeyVerifyException("No such key type "+Integer.toHexString(type)); } }
public void testSimple() throws IOException { final int keys = 10; PubkeyStore pk = new PubkeyStore(); new RAMFreenetStore<DSAPublicKey>(pk, keys); DSAGroup group = Global.DSAgroupBigA; Random random = new MersenneTwister(1010101); HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>(); for(int i=0;i<keys;i++) { DSAPrivateKey privKey = new DSAPrivateKey(group, random); DSAPublicKey key = new DSAPublicKey(group, privKey); byte[] hash = key.asBytesHash(); ByteArrayWrapper w = new ByteArrayWrapper(hash); map.put(w, key.cloneKey()); pk.put(hash, key, false); assertTrue(pk.fetch(hash, false, false, null).equals(key)); } int x = 0; for(Map.Entry<ByteArrayWrapper, DSAPublicKey> entry : map.entrySet()) { x++; assertTrue(pk.fetch(entry.getKey().get(), false, false, null).equals(entry.getValue())); } assert(x == keys); }
public void testSimple() { final int keys = 10; PubkeyStore pk = new PubkeyStore(); new RAMFreenetStore<DSAPublicKey>(pk, keys); GetPubkey pubkeys = new SimpleGetPubkey(pk); DSAGroup group = Global.DSAgroupBigA; Random random = new MersenneTwister(1010101); HashMap<ByteArrayWrapper, DSAPublicKey> map = new HashMap<ByteArrayWrapper, DSAPublicKey>(); for(int i=0;i<keys;i++) { DSAPrivateKey privKey = new DSAPrivateKey(group, random); DSAPublicKey key = new DSAPublicKey(group, privKey); byte[] hash = key.asBytesHash(); ByteArrayWrapper w = new ByteArrayWrapper(hash); map.put(w, key.cloneKey()); pubkeys.cacheKey(hash, key, false, false, false, false, false); assertTrue(pubkeys.getKey(hash, false, false, null).equals(key)); } int x = 0; for(Map.Entry<ByteArrayWrapper, DSAPublicKey> entry : map.entrySet()) { x++; assertTrue(pubkeys.getKey(entry.getKey().get(), false, false, null).equals(entry.getValue())); } assert(x == keys); }
DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC";
DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC";
DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC";
DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC"; DSAPublicKey pubKey2 = new DSAPublicKey(g, privKey2); byte[] pkHash2 = SHA256.digest(pubKey2.asBytes()); InsertableClientSSK ik2 = new InsertableClientSSK(docName, pkHash2, pubKey2, privKey2, ckey, Key.ALGO_AES_PCFB_256_SHA256);
DSAGroup g = Global.DSAgroupBigA; DSAPrivateKey privKey = new DSAPrivateKey(g, random); DSAPublicKey pubKey = new DSAPublicKey(g, privKey); byte[] pkHash = SHA256.digest(pubKey.asBytes()); String docName = "myDOC";