All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.util.SSHBuilder Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for Java 1.5 and later with debug enabled.

There is a newer version: 1.70
Show newest version
package org.bouncycastle.crypto.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.bouncycastle.util.Strings;

class SSHBuilder
{
    private final ByteArrayOutputStream bos = new ByteArrayOutputStream();

    public void u32(long value)
    {
        bos.write((int)((value >>> 24) & 0xFF));
        bos.write((int)((value >>> 16) & 0xFF));
        bos.write((int)((value >>> 8) & 0xFF));
        bos.write((int)(value & 0xFF));
    }

    public void rawArray(byte[] value)
    {
        u32(value.length);
        try
        {
            bos.write(value);
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }

    public void write(byte[] value)
    {
        try
        {
            bos.write(value);
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }

    public void writeString(String str)
    {
        rawArray(Strings.toByteArray(str));
    }

    public byte[] getBytes()
    {
        return bos.toByteArray();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy