Code example for BigInteger

Methods: signumtoByteArray

0
    public byte[] getPublicKeyNetworkFormat() { 
        return stripBigIntegerToNetworkFormat(myExponential);
    } 
     
    private byte[] stripBigIntegerToNetworkFormat(BigInteger exponential) {
        byte[] data = exponential.toByteArray();
        int targetLength = DiffieHellman.modulusLengthInBytes();
        assert(exponential.signum() == 1);
 
        if(data.length != targetLength) {
            byte[] newData = new byte[targetLength];
            if((data.length == targetLength+1) && (data[0] == 0)) {
                // Sign bit 
                System.arraycopy(data, 1, newData, 0, targetLength);
            } else if(data.length < targetLength) {
                System.arraycopy(data, 0, newData, targetLength-data.length, data.length);
            } else { 
                throw new IllegalStateException("Too long!");
            } 
            data = newData;
Contextual code suggestions in your IDE  Get Codota for Java