Files
Brainstorm/Common/src/com/common/security/ISignatureAlgorithm.java

110 lines
5.2 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
/*
* Copyright (c) 2003,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.common.security;
public interface ISignatureAlgorithm extends IAlgorithm, java.io.Externalizable {
/**
* Gets the number of bytes in an optimal block of to-be-signed data. This allows for efficient streaming of data through the signature algorithm.
* @return The optimal size of data to be signed.
*/
public int getOptimalSignatureBlockSize();
/**
* Gets the number of bytes in an optimal block of to-be-verified data. This allows for efficient streaming of data through the signature algorithm.
* @return The optimal size of data to be verified.
*/
public int getOptimalVerificationBlockSize();
/**
* Gets the public algorithm used to verify data.
* @return The public algorithm which can be used for verification.
*/
public ISignatureAlgorithm getPublicSignatureAlgorithm();
/**
* Gets the <strong>exact</strong> number of signed bytes for the given unsigned message size.
* @param unsignedSize The number of unsigned bytes.
* @return The number of signed bytes.
*/
public int getSignedSize(int unsignedSize);
/**
* Gets the maximum number of unsigned bytes for the given signed message size.
* @param unsignedSize The number of signed bytes.
* @return The maximum number of unsigned bytes.
*/
public int getUnsignedSize(int signedSize);
/**
* Gets the public algorithm used for signature verification.
* @return The algorithm used to verify the signatures. This is a publicly accessable algorithm.
*/
public ISignatureAlgorithm getVerifyAlgorithm();
/**
* Gets the public key used for signature verification.
* @return The key used to verify the signatures. This is a publicly accessable key.
*/
public Object getVerifyKey();
/**
* Signs an array of bytes by encrypting them with the private key.
* @param data The input bytes.
* @return The signed (encrypted) data.
* @see #getBlockSize()
*/
public byte[] sign(byte[] data);
/**
* Signs an array of bytes by encrypting them with the private key.
* @param data The input bytes.
* @param dataOffset The offset in the data array to begin encrypting bytes.
* @param dataLength The number of bytes in the data array to encrypt.
* @return The signed (encrypted) data.
* @see #getBlockSize()
*/
public byte[] sign(byte[] data, int dataOffset, int dataLength);
/**
* Signs an array of bytes by encrypting them with the private key and placing them in the supplied buffer.
* <p>Warning: The encrypted byte length will most likely be larger than the unencrypted size.</p>
* @param data The input bytes.
* @param dataOffset The offset in the data array to begin encrypting bytes.
* @param dataLength The number of bytes in the data array to encrypt.
* @param buffer The output bytes.
* @param bufferOffset The offset in the buffer array where the output bytes will begin.
* @return The number of encrypted (signed) bytes placed in the output buffer (includes formatting and padding).
* @see #getBlockSize()
*/
public int sign(byte[] data, int dataOffset, int dataLength, byte[] buffer, int bufferOffset);
/**
* Decrypts an array of bytes using the public key and stores the decrypted bytes in the buffer.
* The output will not include any padding used during encryption.
* <p>NOTE: The number of encrypted data bytes supplied MUST be a multiple of the Block Size (as outputed by the sign method).</p>
* @param data The signed input (encrypted) bytes.
* @return The verify (unencrypted) bytes.
* @see #getBlockSize()
*/
public byte[] verify(byte[] data);
/**
* Decrypts an array of bytes using the public key and stores the decrypted bytes in the buffer.
* The output will not include any padding used during encryption.
* <p>NOTE: The number of encrypted data bytes supplied MUST be a multiple of the Block Size (as outputed by the sign method).</p>
* @param data The signed input (encrypted) bytes.
* @param dataOffset The offset in the data array to begin decrypting bytes.
* @param dataLength The number of bytes in the data array to decrypt.
* @return The verify (unencrypted) bytes.
* @see #getBlockSize()
*/
public byte[] verify(byte[] data, int dataOffset, int dataLength);
/**
* Decrypts an array of bytes using the public key and stores the decrypted bytes in the buffer.
* The output will not include any padding used during encryption.
* <p>NOTE: The number of encrypted data bytes supplied MUST be a multiple of the Block Size (as outputed by the sign method).</p>
* @param data The signed input (encrypted) bytes.
* @param dataOffset The offset in the data array to begin decrypting bytes.
* @param dataLength The number of bytes in the data array to decrypt.
* @param buffer The decrypted output bytes. (This will be filled.)
* @param bufferOffset The offset in the buffer array where the output bytes will begin.
* @return The number of bytes placed in the output buffer.
* @see #getBlockSize()
*/
public int verify(byte[] data, int dataOffset, int dataLength, byte[] buffer, int bufferOffset);
}//ISignatureAlgorithm//