2011-11-04 4 views
-3

암호화 및 암호 해독 클래스를 만들었으니 이제 테스트하고 싶습니다. 암호화 장치는 som 텍스트를 가져 와서 .txt 파일로 암호화합니다. 그러나 그것은 효과가 없습니다.자바 암호화 cannnot 어떤 문자열을 암호화?

public class Encryption extends FilterWriter{ 
private static int INKREMENT = 3; 

protected Encryption(Writer arg0) { 
    super(arg0); 
} 

public void write(String str, int off, int len) throws IOException{ 
    String result = str.substring(0,off); 
    for(int i = off; i<len+off; i++){ 
     result += (char) ((int) str.charAt(i)+ INKREMENT); 
    } 
    result += str.substring(off+len); 
    out.write(result); 
} 
public void write(int c) throws IOException{ 
     out.write(c + INKREMENT); 


} 
public void write(char[] cbuf, int off, int len) throws IOException{ 
    for(int i = off; i < len + off; i++){ 
     cbuf[i] = (char)((int) cbuf[i] + INKREMENT); 
    } 
    out.write(cbuf,off,len); 
} 

}

내 테스트? 나는

Writer out = new Encryption(new BufferedWriter(new FileWriter("text.txt"))); 
+2

인터넷에서 임의의 암호화 코드를 복사하여 사용할 수 없습니다. – JMelnik

+0

암호화? 그래도 여전히 1512 일 경우. – trojanfoe

+0

'INKREMENT'는 매우 안전합니다. – mcfinnigan

답변

0

javax.crypto.CipherOutputStream을 참조 문자열이 text.txt 파일에 암호화되어 저장 얻을 작성하는 것을 잘 모릅니다. 그것은 이미 끝났어.