RawKey rKey = new RawKey("DES", sKey);
Cipher des1;
try{
des1 =Cipher.getInstance("DES","Cryptix");
}
catch(NoSuchAlgorithmException e){
System.out.println("NoSuchAlgortihmException thrown in
LibDes::DES_encryptStr() ");
return null;
}
catch(NoSuchProviderException e){
System.out.println("NoSuchProviderException thrown in
LibDes::DES_encryptStr() ");
return null;
}
try{
if( DES_ENCRYPT == enc){
des1.initEncrypt((java.security.Key)rKey);
}
else{
des1.initDecrypt((java.security.Key)rKey);
}
}
catch(InvalidKeyException e){
System.out.println("InvalidKeyException thrown in
LibDes::DES_encryptStr() ");
return null;
}
catch(KeyException e){
System.out.println("KeyException thrown in LibDes::DES_encryptStr() ");
return null;
}
Any idea is welcomed!
Do you have a Cryptix/ JCE tutorial?
H
Exception in thread "main" xjava.security.IllegalBlockSizeException: DES:
Non-pa
dding cipher in ENCRYPT state with an incomplete final block
at xjava.security.Cipher.updateInternal(Cipher.java:1264)
at xjava.security.Cipher.crypt(Cipher.java:1046)
at xjava.security.Cipher.crypt(Cipher.java:1011)
at LibDes.DES_encryptStr(LibDes.java:149)
at LibDes.main(LibDes.java:200)
The code is slightly different.
Any idea? Tutorial?
Thanx,
H
Cipher des1;
try{
des1 =Cipher.getInstance("DES","Cryptix");
}
catch(NoSuchAlgorithmException e){
System.out.println("NoSuchAlgortihmException thrown in
LibDes::DES_encryptStr() ");
return null;
}
catch(NoSuchProviderException e){
System.out.println("NoSuchProviderException thrown in
LibDes::DES_encryptStr() ");
return null;
}
RawSecretKey rKey = new RawSecretKey(
"DES", sKey);
//alg.initEncrypt(key);
// ect = alg.crypt(Hex.fromString(data[i][1]));
try{
if( DES_ENCRYPT == enc){
des1.initEncrypt(rKey);
}
else{
des1.initDecrypt(rKey);
}
}
catch(InvalidKeyException e){
System.out.println("InvalidKeyException thrown in
LibDes::DES_encryptStr() ");
return null;
}
catch(KeyException e){
System.out.println("KeyException thrown in LibDes::DES_encryptStr() ");
return null;
}
"Horatiu Stanciu" <hor...@softgate.ro> wrote in message
news:aqoglu$b72bu$1...@ID-126238.news.dfncis.de...
Here is the code:
import java.io.*;
import java.security.*;
import java.math.*;
import cryptix.util.core.BI;
import cryptix.util.core.ArrayUtil;
import cryptix.util.core.Hex;
import cryptix.provider.key.*;
import xjava.security.Cipher;
class runDES {
private static int iPadNo = -1;
public runDES(){
}
public static void main (String[] args) {
try {
String sEnc = desCrypt( "l implementations of the equivalent functions of
class Math are not defined to return the bit-for-bit same results. ",
"cucucucu", 8, true );
String sDec = desCrypt( sEnc, "cucucucu", 8, false );
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
}
}
public static String desCrypt(String sInBuff,
String sKey,
int len,
boolean bCryptDirection)
throws Exception{
byte [] bOutBuff;
byte [] bInBuff;
byte [] bKey;
String sOutBuff;
String sPadder = new String( "AAAAAAA" );
/* Padding operation */
int iInBuffLen = sInBuff.length();
System.out.println( "iInBuffLen="+iInBuffLen );
int iPaddLen = (int) Math.IEEEremainder( (double)iInBuffLen, 8);
if( iPaddLen < 0 ){
iPaddLen = 8 - Math.abs(iPaddLen);
}
System.out.print( "iPaddLen: "+iPaddLen );
if( 0 != iPaddLen ){
bInBuff = (sInBuff.concat(sPadder.substring(0,8-iPaddLen))).getBytes();
System.out.println( "C:
"+sInBuff.concat(sPadder.substring(0,8-iPaddLen)) );
}
else{
bInBuff = sInBuff.getBytes();
System.out.println( "C: "+sInBuff );
}
/* get byte[] values from Strings */
bKey = sKey.getBytes();
/* generate byte[] keys */
RawSecretKey key2 = new RawSecretKey( "DES",bKey );
RawKey rkey = (RawKey) key2;
bKey = rkey.getEncoded();
Cipher des = Cipher.getInstance( "DES","Cryptix" );
/* Encrypt or decrypt */
if( bCryptDirection ){
iPadNo = iPaddLen;
des.initEncrypt( key2 );
bOutBuff = des.crypt( bInBuff );
int i = bOutBuff.length;
sOutBuff = new String( bOutBuff,0,i );
System.out.println( "Crypted: "+ sOutBuff);
/// ----------end crypt
}
else{
des.initDecrypt( key2 );
bOutBuff = des.crypt( bInBuff );
int i = bOutBuff.length;
sOutBuff = new String( bOutBuff, 0, i - ( 8 - iPadNo ) );
System.out.println( "Decrypted: "+sOutBuff );
/// ----------end decrypt
}
return sOutBuff;
}
}
"Horatiu Stanciu" <hor...@softgate.ro> wrote in message
news:aqolfb$budck$1...@ID-126238.news.dfncis.de...