Code Examplets phần 8 ppt

38 147 0
Code Examplets phần 8 ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Creating a New Key Pair and Self-signed Certificate This example uses the keytool program to create a new key pair and self-signed certificate for the principal Duke. < keytool -genkey -alias alias -keystore .keystore Enter keystore password: password What is your first and last name? [Unknown]: Duke What is the name of your organizational unit? [Unknown]: JavaSoft What is the name of your organization? [Unknown]: Sun What is the name of your City or Locality? [Unknown]: Cupertino What is the name of your State or Province? [Unknown]: CA What is the two-letter country code for this unit? [Unknown]: US Is correct? [no]: yes Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 31-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/249.html [8/1/2000 7:50:15 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Creating and Signing a JAR File > jar cf myjar.jar MyClass.class > jarsigner -keystore .keystore -storepass password myjar.jar alias Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/250.html [8/1/2000 7:50:16 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Creating a New Policy File Use policytool to create or edit an existing policy file. This is an example of a policy file created using policytool. It grants two permissions. It grants code signed by ``Duke'' permission to read files located in the user's home directory. It also grants code from the location ``http://someserver/myjar.jar'' (regardless of who signed it) to read the ``file.encoding'' system property. > policytool -file .policy keystore ".keystore"; grant signedBy "Duke" { permission java.io.FilePermission "${user.dir}/-", "read"; }; grant codeBase "http://someserver/myjar.jar" { permission java.util.PropertyPermission "file.encoding", "read"; } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/251.html [8/1/2000 7:50:16 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Managing Policy Files The Java Runtime provides default policy files to be used. See http://java.sun.com/products/jdk/1.2/docs /guide/security/PolicyFiles.html for more information. The location of these file is specified in the file java.home/lib/security/java.security. By default, this file specifies two locations: file:/java.home /lib/security/java.policy file:/user.home /lib/security/.java.policy The runtime's policy is the union of entries in these files. To specify an additional policy file, you can add entries to the java.security file: > java -Djava.security.manager -Djava.security.policy=someURL MyApp or specify the addition at runtime: > appletviewer -J-Djava.security.policy=someURL HTMLfile To ignore the policies in the java.security file, and only use the specified policy, use == instead of =: >java -Djava.security.manager -Djava.security.policy==someURL MyApp Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 31-Jul-2000 ] Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/252.html (1 of 2) [8/1/2000 7:50:17 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Creating a Keyed Digest Using MD5 A ``keyed'' digest is one in which a secret key is used to create a digest for a buffer of bytes. You can use different keys to create different digests for the same buffer of bytes. public static byte[] getKeyedDigest(byte[] buffer, byte[] key) { try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(buffer); return md5.digest(key); } catch (NoSuchAlgorithmException e) { } return null; } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 31-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/253.html [8/1/2000 7:50:17 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Getting a Certificate from a Keystore try { KeyStore keyStore = KeyStore.getInstance( KeyStore.getDefaultType()); InputStream in = new FileInputStream(".keystore"); keyStore.load(in, "password".toCharArray()); java.security.cert.Certificate cert = keyStore.getCertificate("Principal"); process(cert); } catch (KeyStoreException e) { } catch (java.security.cert.CertificateException e) { } catch (NoSuchAlgorithmException e) { } catch (java.io.IOException e) { } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/254.html [8/1/2000 7:50:18 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Checking Read/Write Permission for a Directory AccessController.checkPermission(new FilePermission( "/tmp/*", "read,write")); Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/255.html [8/1/2000 7:50:18 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Checking if One Permission Implies Another Permission perm1 = new FilePermission( "/tmp/*", "read,write"); Permission perm2 = new FilePermission( "/tmp/abc", "read"); if (perm1.implies(perm2)) { // perm1 implies perm2 } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/256.html [8/1/2000 7:50:19 AM] java.security Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms Creating a Secure Random Number public static float create(byte[] seed) { SecureRandom sr = new SecureRandom(seed); return sr.nextFloat(); } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World FAQ | Feedback | Map | A-Z Index For more information on Java technology and other software from Sun Microsystems, call: (800) 786-7638 Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first. Copyright © 1995-2000 Sun Microsystems, Inc. All Rights Reserved. Terms of Use. Privacy Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/java.security/257.html [8/1/2000 7:50:20 AM] javax.swing Code Samples Index These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms The Quintessential Swing User Interface This example creates and shows a frame with a button. import java.awt.*; import javax.swing.*; public class BasicUI { public static void main(String[] args) { JButton button = new JButton("Label"); JFrame frame = new JFrame(); // Add button to the frame. frame.getContentPane().add( button, BorderLayout.CENTER); // Set initial size. frame.setSize(300, 300); // Show the frame. frame.setVisible(true); } } Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon [ This page was updated: 19-Jul-2000 ] Products & APIs | Developer Connection | Docs & Training | Online Support Community Discussion | Industry News | Solutions Marketplace | Case Studies Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/javax.swing/181.html (1 of 2) [8/1/2000 7:50:20 AM] [...]... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 182 .html [8/ 1/2000 7:50:20 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 183 .html [8/ 1/2000 7:50:21 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 184 .html [8/ 1/2000 7:50:21 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 185 .html [8/ 1/2000 7:50:22 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 186 .html [8/ 1/2000 7:50:23 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/ 187 .html [8/ 1/2000 7:50:24 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/193.html [8/ 1/2000 7:50: 28 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/194.html (2 of 2) [8/ 1/2000 7:50: 28 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/1 98. html [8/ 1/2000 7:50:30 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples and... Microsystems, call: (80 0) 786 -76 38 Outside the U.S and Canada, dial your country's AT&T Direct Access Number first Copyright © 1995-2000 Sun Microsystems, Inc All Rights Reserved Terms of Use Privacy Policy http://developer.java.sun.com/developer/codesamples/javax.swing/190.html (2 of 2) [8/ 1/2000 7:50:26 AM] Code Samples from the Java Developers Almanac 2000 javax.swing Code Samples Index These code examples . Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/javax.swing/ 182 .html [8/ 1/2000 7:50:20 AM] javax.swing Code Samples Index These code. Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/javax.swing/ 183 .html [8/ 1/2000 7:50:21 AM] javax.swing Code Samples Index These code. Policy. Code Samples from the Java Developers Almanac 2000 http://developer.java.sun.com/developer/codesamples/javax.swing/ 184 .html [8/ 1/2000 7:50:21 AM] javax.swing Code Samples Index These code

Ngày đăng: 06/08/2014, 02:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan