Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

cryptix.openpgp.util
Class PGPMPI  view PGPMPI download PGPMPI.java

java.lang.Object
  extended bycryptix.openpgp.util.PGPMPI

public class PGPMPI
extends java.lang.Object

Read and write BigIntegers in a PGP compatible format.

From RFC 2440:

     3.2. Multi-Precision Integers

     Multi-Precision Integers (also called MPIs) are unsigned integers
     used to hold large integers such as the ones used in cryptographic
     calculations.

     An MPI consists of two pieces: a two-octet scalar that is the length
     of the MPI in bits followed by a string of octets that contain the
     actual integer.

     These octets form a big-endian number; a big-endian number can be
     made into an MPI by prefixing it with the appropriate length.

     Examples:

     (all numbers are in hexadecimal)

     The string of octets [00 01 01] forms an MPI with the value 1. The
     string [00 09 01 FF] forms an MPI with the value of 511.

     Additional rules:

     The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
    
     The length field of an MPI describes the length starting from its
     most significant non-zero bit. Thus, the MPI [00 02 01] is not formed
     correctly. It should be [00 01 01].

Version:
$Revision: 1.2 $

Constructor Summary
private PGPMPI()
           
 
Method Summary
static java.math.BigInteger decode(java.io.DataInput in)
          Read a BigInteger from a stream
static void encode(java.io.DataOutput out, java.math.BigInteger x)
          Write a BigInteger to a stream
static byte[] toFixedLenByteArray(java.math.BigInteger x, int resultByteLen)
          Fit (stretch or shrink) the given positive BigInteger into a byte[] of resultByteLen bytes without losing precision.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PGPMPI

private PGPMPI()
Method Detail

decode

public static java.math.BigInteger decode(java.io.DataInput in)
                                   throws java.io.IOException
Read a BigInteger from a stream


encode

public static void encode(java.io.DataOutput out,
                          java.math.BigInteger x)
                   throws java.io.IOException
Write a BigInteger to a stream


toFixedLenByteArray

public static byte[] toFixedLenByteArray(java.math.BigInteger x,
                                         int resultByteLen)
Fit (stretch or shrink) the given positive BigInteger into a byte[] of resultByteLen bytes without losing precision.