며칠 전 Jasypt에서 발생한 문제에 대해 질문했습니다. EncryptionOperationNotPossibleException을 던지는 큰 프로그램을 참조했습니다. 글쎄, 난 아직도 문제를 알아낼 수 없다. 무슨 일이 일어나고 있는지를 알 수 있습니다. (그리고 이것이 어떻게 작동하는지에 대한 통찰력을 제공합니다.)Jasypt EncryptionOperationNotPossibleException
Step 1: Connection
Client Connects
Server Callback: connection(Selection key)
Server Sends Cipher
Client Receives Cipher
Sends encrypted "connection" message "YYPgDOGffgxu6aahZyNSgw=="
Client Receives Encrypted msg "YYPgDOGffgxu6aahZyNSgw=="
Client Throws EncryptionOperationNotPossibleExcepton
at line 45
이것은 실제로 보라색입니다. 문자 인코딩에 문제가있을 수 있지만 확실하지 않습니다. 서버와 클라이언트는 현재 같은 컴퓨터에서 실행되고 있으며 전적으로 US-ASCII를 사용하고 있습니다. 여기
클라이언트 : 여기
public static String CHAR_ENC_B = "US-ASCII";
public static String cipher = null;
public static void main(String[] argv) throws UnknownHostException {
final BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
AbstractBlockingClient client = new AbstractBlockingClient(InetAddress.getByName("127.0.0.1"),4444) {
@Override
protected void messageReceived(ByteBuffer message) {
if (cipher==null) {
cipher=bb2str(message);
textEncryptor.setPassword(cipher);
System.out.println("Cipher(20):"+cipher);}
else {
System.out.println("Raw Message(22):"+bb2str(message));
System.out.println("Decrypted(23):"+textEncryptor.decrypt(bb2str(message)));
String tosend = textEncryptor.encrypt("Test Reply");
try {
this.write(textEncryptor.encrypt("Test Reply").getBytes(CHAR_ENC_B));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
@Override
protected void disconnected() {
}
@Override
protected void connected(boolean alreadyConnected) {
}
};
client.run();
}
서버된다 다음은 관련 코드입니다
public static String CHAR_ENC_B = "US-ASCII";
public static void main(String[] argv) {
//Create the server:
AbstractServer server = new AbstractServer(4444) {
@Override
protected void messageReceived(ByteBuffer message, SelectionKey key) {
System.out.println("Recieved Raw Message(18):"+bb2str(message));
System.out.println("Recieved Decrypted Message(19):"+decrypt_string(getCS(key).ekey,bb2str(message)));
ClientSelector replacement = process_message(decrypt_string(getCS(key).ekey,bb2str(message)),getCS(key));
key.attach(replacement);
}
@Override
protected void connection(SelectionKey key) {
ClientSelector newone = new ClientSelector(key,"","","");
newone.ip = ((SocketChannel)key.channel()).socket().getRemoteSocketAddress().toString();
key.attach(newone);
this.write(key,newone.ekey.getBytes());
String tosend = encrypt_string(newone.ekey,"a");
this.write(key,tosend.getBytes());
System.out.println("Cipher:"+newone.ekey);
System.out.println("Encrypted String Sent(34):"+tosend);
}
@Override
protected void disconnected(SelectionKey key) {
}
@Override
protected void started(boolean alreadyStarted) {
System.out.println("SERVER STARTED");
}
@Override
protected void stopped() {
}
};
server.run();
}
public static String decrypt_string(String key, String msg) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(key);
return textEncryptor.decrypt(msg);
}
public static String encrypt_string(String key, String msg) {
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
textEncryptor.setPassword(key);
return textEncryptor.encrypt(msg);
}
이 실제로하려고하는 메시지를 전송하는 것이 아니라, 그것을이다 시작하기 좋은 곳.
일부 정보
:ClientSelector
는 서버가 (등 사용자 이름, 암호, IP,과)에 얘기하고
bb2str
가
String
-
ByteBuffer
변환 자 식별 할 수있는 클래스입니다.
도움이 될만한 의견이 있습니다. 나는 그것이 마지막 하나와 같은 어리석은 실수가 아니길 바래! 감사합니다.
편집: 내가 bb2str에 대한 코드를 추가했습니다 :
public static String bb2str(ByteBuffer bytebuff) {
byte[] bytearr = new byte[bytebuff.remaining()];
bytebuff.get(bytearr);
String s = null;
try {s = new String(bytearr,"US-ASCII");}
catch (UnsupportedEncodingException e) {e.printStackTrace();}
return s;
}
'bb2str()'메소드를 사용하여 기본 64 출력을 버퍼에서 끝까지 정확하게 검색 할 수 있습니까? 구현을 게시 할 수 있습니까? –
설명서에 EncryptionOperationNotPossibleExcepton의 가능한 원인에 대한 설명이 있습니까? 나열된 모든 가능한 원인을 확인 했습니까? – rossum
설명서는 EncryptionOperationNotPossibleException에 대해 매우 모호합니다. 보안상의 이유로 오류 정보를 의도적으로 공유하지 않습니다. 이 예외는 Java의 암호화 측에서는 예외가있는 경우에 발생합니다. 정말 일반적입니다. @owlstead - 코드를 bb2str에 게시 하겠지만 클라이언트와 서버 모두 암호를 알고 있기 때문에 제대로 작동 함을 알 수 있습니다. 완벽하게 전송됩니다. 그래서 그게 문제라고 생각하지 않습니다. –