Package freenet.crypt

Examples of freenet.crypt.DSAPublicKey


    if (logMINOR)
      Logger.minor(this, "Getting pubkey: " + HexUtil.bytesToHex(hash));

    if (USE_RAM_PUBKEYS_CACHE) {
      synchronized (cachedPubKeys) {
        DSAPublicKey key = cachedPubKeys.get(w);
        if (key != null) {
          cachedPubKeys.push(w, key);
          if (logMINOR)
            Logger.minor(this, "Got " + HexUtil.bytesToHex(hash) + " from in-memory cache");
          return key;
        }
      }
    }
    try {
      DSAPublicKey key = null;
      if(pubKeyClientcache != null && canReadClientCache)
        key = pubKeyClientcache.fetch(hash, false, false, meta);
      if(node.oldPKClientCache != null && canReadClientCache && key == null) {
        PubkeyStore pks = node.oldPKClientCache;
        if(pks != null) key = pks.fetch(hash, false, false, meta);
View Full Code Here


  public void cacheKey(byte[] hash, DSAPublicKey key, boolean deep, boolean canWriteClientCache, boolean canWriteDatastore, boolean forULPR, boolean writeLocalToDatastore) {
    if (logMINOR)
      Logger.minor(this, "Cache key: " + HexUtil.bytesToHex(hash) + " : " + key);
    ByteArrayWrapper w = new ByteArrayWrapper(hash);
    synchronized (cachedPubKeys) {
      DSAPublicKey key2 = cachedPubKeys.get(w);
      if ((key2 != null) && !key2.equals(key))
        throw new IllegalArgumentException("Wrong hash?? Already have different key with same hash!");
      cachedPubKeys.push(w, key);
      while (cachedPubKeys.size() > MAX_MEMORY_CACHED_PUBKEYS)
        cachedPubKeys.popKey();
    }
View Full Code Here

    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));
    }
  }
View Full Code Here

    if (key instanceof NodeCHK) {
      kb = fetch(key, false, canReadClientCache, canWriteClientCache, canWriteDatastore, null);
    } else if (key instanceof NodeSSK) {
      NodeSSK sskKey = (NodeSSK) key;
      DSAPublicKey pubKey = sskKey.getPubKey();
      if (pubKey == null) {
        pubKey = getPubKey.getKey(sskKey.getPubKeyHash(), canReadClientCache, offersOnly, null);
        if (logMINOR)
          Logger.minor(this, "Fetched pubkey: " + pubKey);
        try {
View Full Code Here

    else
      throw new IllegalStateException("Don't know what to do with "+key);
  }

  public ClientKeyBlock fetch(ClientSSK clientSSK, boolean canReadClientCache, boolean canWriteClientCache, boolean canWriteDatastore) throws SSKVerifyException {
    DSAPublicKey key = clientSSK.getPubKey();
    if(key == null) {
      key = getPubKey.getKey(clientSSK.pubKeyHash, canReadClientCache, false, null);
    }
    if(key == null) return null;
    clientSSK.setPublicKey(key);
View Full Code Here

      } 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);
      }
View Full Code Here

  }
 
  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);
    }
  }
View Full Code Here

    } catch(IllegalArgumentException e) {
      // DSAPrivateKey is invalid
      Logger.error(InsertableClientSSK.class, "Caught "+e, 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);
  }
View Full Code Here

  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);
    }
View Full Code Here

    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()) {
View Full Code Here

TOP

Related Classes of freenet.crypt.DSAPublicKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.