菜鳥学JAVAの練習(電子署名生成)
8793 ワード
自分で電子署名を生成します。
実験報告をただ見ているだけで悩んでいるのではないでしょうか?あなたはまだ他の人のコードのせいで悩んでいますか?自分の名前の電子タグを作る方法を教えます。
第一歩は、先生が自分の名前のバイトコードになります。
実験報告をただ見ているだけで悩んでいるのではないでしょうか?あなたはまだ他の人のコードのせいで悩んでいますか?自分の名前の電子タグを作る方法を教えます。
第一歩は、先生が自分の名前のバイトコードになります。
public class Test {
public static void main(String[] args) {
String str = " ";
System.out.println(Arrays.toString(str.getBytes()));
// :[-27, -68, -96, -26, -66, -77, -25, -112, -86]
}
}
第二ステップ、実現public class ObservObject {
private final byte[] token = {
-27, -68, -96, -26, -66, -77, -25, -112, -86};
// public void showCopyRight() {
// try {
// System.out.println(new String(token,"UTF-8"));
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// }
// , , 。 : toString
@Override // toString ,
public String toString() {
return "hahaha";
}
public final String toString(String tag) {
// toString , final, 。( final )
// ( , ) .class , OK 。 。
switch (tag) {
case "whoami":
try {
return new String(token,"UTF-8");// utf-8
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
default:
return this.toString();
}
}
}
// ,
シーンクラスpublic class Main {
public static void main(String[] args) throws UnsupportedEncodingException{
ObservObject observObject = new ObservObject();
System.out.println(observObject);// hahaha
System.out.println(observObject.toString("whoami"));// whoami
}
}
以上は小さいトレーナーです。勉強の退屈な過程を消して、興味のある学生は試しに遊んでみてもいいです。前に勉強したものに対して小さい回顧をします。