powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / DES шифрование в java
3 сообщений из 3, страница 1 из 1
DES шифрование в java
    #38490982
В ходе шифрования с помощью DES возникла проблема.
Использую следующий код:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
    private byte[] encryptDES() throws Exception
    {
byte[] inputBytes, byte[] keyValue
        String algorithm = "DES";
        String transformation = "DES";
        DESKeySpec keySpec = new DESKeySpec(keyValue);
        SecretKey key = SecretKeyFactory.getInstance(algorithm).generateSecret(keySpec);
        Cipher encrypter = Cipher.getInstance(transformation);
        encrypter.init(Cipher.ENCRYPT_MODE, key);
        return encrypter.doFinal(inputBytes);
    }
...
Рейтинг: 0 / 0
DES шифрование в java
    #38497831
usa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Телепатов тут нет, опишите проблему
...
Рейтинг: 0 / 0
DES шифрование в java
    #38497875
Sergunka
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
usaТелепатов тут нет, опишите проблему

Судя по всему чел лажанулся на подложке - обычное явление для новичков

Код должен выглядеть примерно так

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
try{
 
		    KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
		    SecretKey myDesKey = keygenerator.generateKey();
 
		    Cipher desCipher;
 
		    // Create the cipher 
		    desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
 
		    // Initialize the cipher for encryption
		    desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
 
		    //sensitive information
		    byte[] text = "No body can see me".getBytes();
 
		    System.out.println("Text [Byte Format] : " + text);
		    System.out.println("Text : " + new String(text));
 
		    // Encrypt the text
		    byte[] textEncrypted = desCipher.doFinal(text);
 
		    System.out.println("Text Encryted : " + textEncrypted);
 
		    // Initialize the same cipher for decryption
		    desCipher.init(Cipher.DECRYPT_MODE, myDesKey);
 
		    // Decrypt the text
		    byte[] textDecrypted = desCipher.doFinal(textEncrypted);
 
		    System.out.println("Text Decryted : " + new String(textDecrypted));
 
		}catch(NoSuchAlgorithmException e){
			e.printStackTrace();



Как из примера здесь
http://www.mkyong.com/java/jce-encryption-data-encryption-standard-des-tutorial/

Если решите использовать симметричный ключ AES то можете глянуть у меня
http://vyatkins.wordpress.com/2013/12/06/cryptography-advanced-encryption-standard-aes-and-hash-java-based-examples/
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / DES шифрование в java
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]