Home > Back-end >  Urgent urgent ask ace to solve Java delphi7DES encryption algorithm code conversion issues
Urgent urgent ask ace to solve Java delphi7DES encryption algorithm code conversion issues

Time:11-17

Package COM. CCB. EnDecryptAlgorithm;

Import the Java. IO. UnsupportedEncodingException;
The import java.net.URLEncoder;
Import the Java. Security. InvalidAlgorithmParameterException;
Import the Java. Security. InvalidKeyException;
Import the Java. Security. NoSuchAlgorithmException;
Import the Java. Security. NoSuchProviderException;
Import the Java. Security. Security;
The import javax.mail. Crypto. BadPaddingException;
The import javax.mail. Crypto. Cipher;
The import javax.mail. Crypto. IllegalBlockSizeException;
The import javax.mail. Crypto. NoSuchPaddingException;
The import javax.mail. Crypto. ShortBufferException;
The import javax.mail. Crypto. Spec. SecretKeySpec;
The import org. Bouncycastle. Jce. Provider. BouncyCastleProvider;
The import sun. Misc. BASE64Encoder;

Public class MCipherEncryptor
{
Private String the encryptKey="@ 9 r e8Y3 #";

The static
{
If (Security. GetProvider (" BC ")==null)
{
Security. AddProvider (new BouncyCastleProvider ());
}
}

Public MCipherEncryptor (String key)
{
Enclosing the encryptKey=key. The substring (0, 8).
}

Public String getEncryptKey () {
Return this. The encryptKey;
}

Public void setEncryptKey (String) the encryptKey {
Enclosing the encryptKey=the encryptKey. Substring (0, 8).
}

Private static byte [] wrapBytes (byte [] srcBytes, byte [] wrapKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException
{
SecretKeySpec key=new SecretKeySpec (wrapKey, "DES");

Cipher Cipher=Cipher. GetInstance (" DES/the ECB/PKCS5Padding ", "BC");

Cipher. The init (1, key);

Byte [] cipherText=cipher. DoFinal (srcBytes);

Return cipherText.
}

Public static String EncodeBase64String (byte [] srcBytes)
{
BASE64Encoder en=new BASE64Encoder ();
String base64Result=en. Encode (srcBytes);
Return base64Result;
}

Public String getEncodeString (String srcString)
Throws InvalidKeyException NoSuchAlgorithmException, NoSuchPaddingException ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException, UnsupportedEncodingException
{
Byte [] cipherBytes=wrapBytes (srcString getBytes (" ISO - 8859-1 "), enclosing the encryptKey. GetBytes (" ISO - 8859-1 "));
String basedString=EncodeBase64String (cipherBytes);
String resultString=basedString. ReplaceAll (\ \ "" +", ", ");
Return URLEncoder. Encode (resultString, "ISO - 8859-1");
}

Public String doEncrypt (String srcString)
Throws InvalidKeyException NoSuchAlgorithmException, NoSuchPaddingException ShortBufferException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException, UnsupportedEncodingException
{
Byte [] cipherBytes=wrapBytes (srcString getBytes (" utf - 16 "), enclosing the encryptKey. GetBytes (" ISO - 8859-1 "));

String basedString=EncodeBase64String (cipherBytes);
String resultString=basedString. ReplaceAll (\ \ "" +", ", ");

Return URLEncoder. Encode (resultString, "iso - 8859-1");
}
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Above is the Java jar decompiled des encryption code, bosses how to code delphi7, genuflect is begged the encryption are the same,,


There are bosses,??????? I met the code conversion problem, a problem too, ask bosses to give directions,,,
Very grateful, grateful,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

CodePudding user response:

Top!!!!!!!!!!!!!!!

CodePudding user response:

Java string is unicode, D7 is DBCS string coding, the same algorithm, you use a WideString,

CodePudding user response:

Delphi itself does not provide the DES algorithm
Standard of des algorithm (ECB mode) may refer to http://code1.okbase.net/codefile/DESUnit.pas_2013080823367_2.htm
Encrypted characters with WideString, password in String (that is, AnsiString);
Encryption scheme using the PKCS5Padding filling pattern, so if be encrypted string of bytes less than 8 multiples, lack of filling a value of 1 1 byte, short of 2 bytes filled 2 2, the rest of the analogy, if the number of bytes of the string itself is just 8 multiples, are filled with eight number 8

CodePudding user response:

Decryption time corresponding to the corresponding filling up of bytes,

CodePudding user response:

reference 4 floor BlueStorm response:
decryption time corresponding to the corresponding filling up of bytes,

Bosses have any specific implementation of

CodePudding user response:

I have no specific implementation,
Information I provide the implementation of the should be enough for you,

CodePudding user response:

refer to 6th floor BlueStorm response:
I have no specific implementation,
I provide information should be enough you concrete realization,

Okay, I study again

CodePudding user response:

There should be a DES algorithm unit download on BBS, I download resources have an encrypted in the unit should be based on DES algorithm

nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related