哥们,我这里有N多种加密算法java源程序,先加分,我给你发过去。我先给你贴出来一部分:)
/*
* Copyright (c) 1995, 1996, 1997 Systemics Ltd
* on behalf of the Cryptix Development Team. All rights reserved.
*/package cryptix.security;import java.io.PrintStream;/**
* DES is a block cipher with an 8 byte block size. The key length
* is 8 bytes, but only 56 bits are used as the parity bit in each
* byte is ignored.
* <P>
* This algorithm has been seriously analysed over the last 30 years,
* and no significant weaknesses have been reported. It's only flaw
* is that the key length of 56 bits makes it relatively easy to
* brute-force it. To overcome this near-fatal flaw, it is recommended
* that DES be used in triple-DES mode. Need reference here...
*
* <P>
* <b>References</b>
*
* <P>
* DES was written by IBM and first released in 1976.
* See
* <a href="mailto:[email protected]">Bruce Schneier</a>,
* "Chapter 12 Data Encryption Standard,"
* <cite>Applied Cryptography</cite>,
* Wiley 2nd Ed, 1996
* for detailed information. The algorithm is freely usable.
*
* <P>
* <bold>Copyright</bold> © 1995, 1996, 1997
* <a href="http://www.systemics.com/">Systemics Ltd</a>
* on behalf of the
* <a href="http://www.systemics.com/docs/cryptix/">
* Cryptix Development Team</a>.
* All rights reserved.
*
* <P>
* @author Geoffrey Keating (this Java implementation)
* @author Eric Young (SPtrans)
* @see BlockCipher
*/
public final class DES extends BlockCipher
{
private static final int REQUIRED_LIB_MAJOR_VER = 1;
private static final int REQUIRED_LIB_MINOR_VER = 11;
private static final String LIBRARY_NAME = "des"; private static boolean native_link_ok = false;
private static boolean native_lib_loaded = false;
private static String native_link_err = "Class never loaded"; static
{
// load the DLL or shared library that contains the native code
// implementation of the des block cipher.
try
{
System.loadLibrary( LIBRARY_NAME );
native_lib_loaded = true;
try
{
if ( ( getLibMajorVersion() != REQUIRED_LIB_MAJOR_VER ) ||
( getLibMinorVersion() < REQUIRED_LIB_MINOR_VER ) )
{
native_link_err = "The " +
LIBRARY_NAME + " native library " +
getLibMajorVersion() + "." +
getLibMinorVersion() +
" is too old to use. Version " +
REQUIRED_LIB_MAJOR_VER + "." +
REQUIRED_LIB_MINOR_VER +
" required.";
}
else
{
native_link_ok = true;
native_link_err = null;
}
}
catch ( UnsatisfiedLinkError ule )
{
native_link_err = "The " +
LIBRARY_NAME +
" native library is too old to use." +
"Version " +
REQUIRED_LIB_MAJOR_VER + "." +
REQUIRED_LIB_MINOR_VER +
" required.";
}
}
catch ( UnsatisfiedLinkError ule )
{
native_link_err = "The " +
LIBRARY_NAME + " native library was not found.";
}
} public final static boolean
hasFileLibraryLoaded()
{
return native_lib_loaded;
} public final static boolean
isLibraryCorrect()
{
return native_link_ok;
} public final static String
getLinkErrorString()
{
return native_link_err;
} /**
* The length of a block - DEPRECATED - use blockLength() instead.
*/
public static final int BLOCK_LENGTH = 8; /**
* The length of a the user key - DEPRECATED - use keyLength() instead.
*/
public static final int KEY_LENGTH = 8; private static final int ROUNDS = 16; /* The size of the key after it has been scheduled. */
static private final int INTERNAL_KEY_LENGTH = ROUNDS*2;
//
// This was in the original stub, but appears to be wrong.
//
// This is the length of the internal buffer for the native code.
// private static final int INTERNAL_KEY_LENGTH = 128; /**
* Return the block length of this cipher.
* @return the block length in bytes is 8
*/
public int
blockLength()
{
return BLOCK_LENGTH;
} /**
* Return the key length for this cipher.
* @returns the key length in bytes is 8
*/
public int
keyLength()
{
return KEY_LENGTH;
} /**
* Create a DES block cipher from a key in a byte array.
* The byte array must be keyLength bytes long.
* @param userKey the user key in a byte[ keyLength() ] array
* @throws CryptoError if length of key array is wrong
* @throws UnsatisfiedLinkError if the library is not of the correct version
*/
public DES( byte userKey[] )
{
if ( userKey.length != KEY_LENGTH )
throw new CryptoError( "DES: User key length wrong" ); // this was in the original stub but appears wrong.
// ks = new byte[INTERNAL_KEY_LENGTH]; if (native_link_ok)
set_ks(userKey);
else
java_ks(userKey);
} //
// Encrypt a block.
// The in and out buffers can be the same.
// @param in The data to be encrypted.
// @param in_offset The start of data within the in buffer.
// @param out The encrypted data.
// @param out_offset The start of data within the out buffer.
//
protected void
blockEncrypt( byte in[], int in_offset, byte out[], int out_offset )
{
if ( key == null )
throw new CryptoError( "DES: User key not set" ); if (native_link_ok)
do_des( in, in_offset, out, out_offset, true );
else
java_encrypt( in, in_offset, out, out_offset, true );
}
continue;
/*
* Copyright (c) 1995, 1996, 1997 Systemics Ltd
* on behalf of the Cryptix Development Team. All rights reserved.
*/package cryptix.security;import java.io.PrintStream;/**
* DES is a block cipher with an 8 byte block size. The key length
* is 8 bytes, but only 56 bits are used as the parity bit in each
* byte is ignored.
* <P>
* This algorithm has been seriously analysed over the last 30 years,
* and no significant weaknesses have been reported. It's only flaw
* is that the key length of 56 bits makes it relatively easy to
* brute-force it. To overcome this near-fatal flaw, it is recommended
* that DES be used in triple-DES mode. Need reference here...
*
* <P>
* <b>References</b>
*
* <P>
* DES was written by IBM and first released in 1976.
* See
* <a href="mailto:[email protected]">Bruce Schneier</a>,
* "Chapter 12 Data Encryption Standard,"
* <cite>Applied Cryptography</cite>,
* Wiley 2nd Ed, 1996
* for detailed information. The algorithm is freely usable.
*
* <P>
* <bold>Copyright</bold> © 1995, 1996, 1997
* <a href="http://www.systemics.com/">Systemics Ltd</a>
* on behalf of the
* <a href="http://www.systemics.com/docs/cryptix/">
* Cryptix Development Team</a>.
* All rights reserved.
*
* <P>
* @author Geoffrey Keating (this Java implementation)
* @author Eric Young (SPtrans)
* @see BlockCipher
*/
public final class DES extends BlockCipher
{
private static final int REQUIRED_LIB_MAJOR_VER = 1;
private static final int REQUIRED_LIB_MINOR_VER = 11;
private static final String LIBRARY_NAME = "des"; private static boolean native_link_ok = false;
private static boolean native_lib_loaded = false;
private static String native_link_err = "Class never loaded"; static
{
// load the DLL or shared library that contains the native code
// implementation of the des block cipher.
try
{
System.loadLibrary( LIBRARY_NAME );
native_lib_loaded = true;
try
{
if ( ( getLibMajorVersion() != REQUIRED_LIB_MAJOR_VER ) ||
( getLibMinorVersion() < REQUIRED_LIB_MINOR_VER ) )
{
native_link_err = "The " +
LIBRARY_NAME + " native library " +
getLibMajorVersion() + "." +
getLibMinorVersion() +
" is too old to use. Version " +
REQUIRED_LIB_MAJOR_VER + "." +
REQUIRED_LIB_MINOR_VER +
" required.";
}
else
{
native_link_ok = true;
native_link_err = null;
}
}
catch ( UnsatisfiedLinkError ule )
{
native_link_err = "The " +
LIBRARY_NAME +
" native library is too old to use." +
"Version " +
REQUIRED_LIB_MAJOR_VER + "." +
REQUIRED_LIB_MINOR_VER +
" required.";
}
}
catch ( UnsatisfiedLinkError ule )
{
native_link_err = "The " +
LIBRARY_NAME + " native library was not found.";
}
} public final static boolean
hasFileLibraryLoaded()
{
return native_lib_loaded;
} public final static boolean
isLibraryCorrect()
{
return native_link_ok;
} public final static String
getLinkErrorString()
{
return native_link_err;
} /**
* The length of a block - DEPRECATED - use blockLength() instead.
*/
public static final int BLOCK_LENGTH = 8; /**
* The length of a the user key - DEPRECATED - use keyLength() instead.
*/
public static final int KEY_LENGTH = 8; private static final int ROUNDS = 16; /* The size of the key after it has been scheduled. */
static private final int INTERNAL_KEY_LENGTH = ROUNDS*2;
//
// This was in the original stub, but appears to be wrong.
//
// This is the length of the internal buffer for the native code.
// private static final int INTERNAL_KEY_LENGTH = 128; /**
* Return the block length of this cipher.
* @return the block length in bytes is 8
*/
public int
blockLength()
{
return BLOCK_LENGTH;
} /**
* Return the key length for this cipher.
* @returns the key length in bytes is 8
*/
public int
keyLength()
{
return KEY_LENGTH;
} /**
* Create a DES block cipher from a key in a byte array.
* The byte array must be keyLength bytes long.
* @param userKey the user key in a byte[ keyLength() ] array
* @throws CryptoError if length of key array is wrong
* @throws UnsatisfiedLinkError if the library is not of the correct version
*/
public DES( byte userKey[] )
{
if ( userKey.length != KEY_LENGTH )
throw new CryptoError( "DES: User key length wrong" ); // this was in the original stub but appears wrong.
// ks = new byte[INTERNAL_KEY_LENGTH]; if (native_link_ok)
set_ks(userKey);
else
java_ks(userKey);
} //
// Encrypt a block.
// The in and out buffers can be the same.
// @param in The data to be encrypted.
// @param in_offset The start of data within the in buffer.
// @param out The encrypted data.
// @param out_offset The start of data within the out buffer.
//
protected void
blockEncrypt( byte in[], int in_offset, byte out[], int out_offset )
{
if ( key == null )
throw new CryptoError( "DES: User key not set" ); if (native_link_ok)
do_des( in, in_offset, out, out_offset, true );
else
java_encrypt( in, in_offset, out, out_offset, true );
}
continue;
这个DES源程序是有两部分功能,第一,可以加载其它语言写的DLL,如果加载失败会用下面写的代码实现!
分数有的是。 另外 linux/unix 有问题可以直接解答