import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{
成都網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、成都網(wǎng)站建設(shè)、微信開發(fā)、微信平臺小程序開發(fā)、集團成都定制網(wǎng)站等服務(wù)項目。核心團隊均擁有互聯(lián)網(wǎng)行業(yè)多年經(jīng)驗,服務(wù)眾多知名企業(yè)客戶;涵蓋的客戶類型包括:成都發(fā)電機租賃等眾多領(lǐng)域,積累了大量豐富的經(jīng)驗,同時也獲得了客戶的一致贊揚!
public static void main(String[] argv) {
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();
}catch(NoSuchPaddingException e){
e.printStackTrace();
}catch(InvalidKeyException e){
e.printStackTrace();
}catch(IllegalBlockSizeException e){
e.printStackTrace();
}catch(BadPaddingException e){
e.printStackTrace();
}
}
}
按照題目要求編寫的Circle類的Java程序如下(文件名Circle.java)
public class Circle{
private double radius;
Circle(){
radius=0;
}
Circle(double r){
radius=r;
}
double getRadius(){
return radius;
}
double getLength(){
return 2*Math.PI*radius;
}
double getArea(){
return Math.PI*radius*radius;
}
void disp(){
System.out.println("圓的半徑為"+getRadius());
System.out.println("圓的周長為"+getLength());
System.out.println("圓的面積為"+getArea());
}
}
下面是Circle類的測試類Test(文件名Test.java 要運行需要和Circle.java放在同一包內(nèi))
public class Test{
public static void main(String[] args){
Circle c=new Circle(2.5);
c.disp();
}
}
只要自己的電腦安裝了jdk環(huán)境,任何地方都可以進行java代碼的編寫的,記事本也可以。