예제 #1
0
 public static PublicKey decodePublicKey(DataInput buffer, byte[] receivedRawPublicKey)
     throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {
   buffer.readBytes(receivedRawPublicKey);
   X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(receivedRawPublicKey);
   KeyFactory keyFactory = KeyFactory.getInstance("DSA");
   final PublicKey receivedPublicKey = keyFactory.generatePublic(pubKeySpec);
   return receivedPublicKey;
 }
  @Override
  public void copyBytes(DataInput input, long numBytes) throws IOException {
    assert numBytes >= 0 : "numBytes=" + numBytes;

    while (numBytes > 0) {
      if (bufferPosition == bufferLength) {
        currentBufferIndex++;
        switchCurrentBuffer();
      }

      int toCopy = currentBuffer.length - bufferPosition;
      if (numBytes < toCopy) {
        toCopy = (int) numBytes;
      }
      input.readBytes(currentBuffer, bufferPosition, toCopy, false);
      numBytes -= toCopy;
      bufferPosition += toCopy;
    }
  }