The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.security  [30 examples] > Signatures  [4 examples]

e203. Creating a Signature

See also e198 Generating a Public/Private Key Pair and e202 Listing All Available Signature Algorithms.
    // Returns the signature for the given buffer of bytes using the private key.
    public static byte[] createSignature(PrivateKey key, byte[] buffer) {
        try {
            Signature sig = Signature.getInstance(key.getAlgorithm());
            sig.initSign(key);
            sig.update(buffer, 0, buffer.length);
            return sig.sign();
        } catch (SignatureException e) {
        } catch (InvalidKeyException e) {
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }

 Related Examples
e202. Listing All Available Signature Algorithms
e204. Verifying a Signature
e205. Signing a Java Object

See also: Key Store    Message Digests    Permissions    Policy Files    Public and Private Keys   


© 2002 Addison-Wesley.