xref: /aosp_15_r20/development/samples/KeyChainDemo/_index.html (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
1*90c8c64dSAndroid Build Coastguard Worker<p>This is a demo application highlighting how to use the KeyChain APIs introduced in API Level 14.</p>
2*90c8c64dSAndroid Build Coastguard Worker
3*90c8c64dSAndroid Build Coastguard Worker<p>The source code for this demo app shows how to install a PKCS12 key chain stored in the assets folder,
4*90c8c64dSAndroid Build Coastguard Worker grant permission to the app to use the installed key chain and finally display the certificate and
5*90c8c64dSAndroid Build Coastguard Worker private key info.  The app also has a simple implementation of a web server listening to requests
6*90c8c64dSAndroid Build Coastguard Worker at an SSL socket using the same certificate in the key chain.
7*90c8c64dSAndroid Build Coastguard Worker</p>
8*90c8c64dSAndroid Build Coastguard Worker
9*90c8c64dSAndroid Build Coastguard Worker<p>The application includes the following key classes:</p>
10*90c8c64dSAndroid Build Coastguard Worker<ul>
11*90c8c64dSAndroid Build Coastguard Worker  <li><a href="src/com/example/android/keychain/KeyChainDemoActivity.html"><code>KeyChainDemoActivity</code></a>
12*90c8c64dSAndroid Build Coastguard Worker    &mdash; the main <code>Activity</code> that is used to install the key chain and start/stop
13*90c8c64dSAndroid Build Coastguard Worker    the web server.  </li>
14*90c8c64dSAndroid Build Coastguard Worker  <li><a href="src/com/example/android/keychain/SecureWebServer.html"><code>SecureWebServer</code></a>
15*90c8c64dSAndroid Build Coastguard Worker    &mdash; a single thread web server listening at port 8080 for <code>https://localhost:8080</code> request</li>
16*90c8c64dSAndroid Build Coastguard Worker  <li><a href="src/com/example/android/keychain/SecureWebServerService.html"><code>SecureWebServerService</code></a>
17*90c8c64dSAndroid Build Coastguard Worker    &mdash; a <code>Service</code> that runs the web server in the foreground.</li>
18*90c8c64dSAndroid Build Coastguard Worker</ul>
19*90c8c64dSAndroid Build Coastguard Worker
20*90c8c64dSAndroid Build Coastguard Worker<p>If you are developing an application that uses the KeyChain APIs,
21*90c8c64dSAndroid Build Coastguard Worker remember that the feature is supported only on Android 4.0 (API level 14) and
22*90c8c64dSAndroid Build Coastguard Worker higher versions of the platform. To ensure that your application can only be
23*90c8c64dSAndroid Build Coastguard Worker installed on devices that are running Android 4.0, remember to add the
24*90c8c64dSAndroid Build Coastguard Worker following to the application's manifest:</p>
25*90c8c64dSAndroid Build Coastguard Worker<ul>
26*90c8c64dSAndroid Build Coastguard Worker  <li><code>&lt;uses-sdk android:minSdkVersion="14" /&gt;</code>, which
27*90c8c64dSAndroid Build Coastguard Worker    indicates to the Android platform that your application requires
28*90c8c64dSAndroid Build Coastguard Worker    Android 4.0 or higher. For more information, see <a
29*90c8c64dSAndroid Build Coastguard Worker    href="../../../guide/appendix/api-levels.html">API Levels</a> and the
30*90c8c64dSAndroid Build Coastguard Worker    documentation for the <a
31*90c8c64dSAndroid Build Coastguard Worker    href="../../../guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a>
32*90c8c64dSAndroid Build Coastguard Worker    element.</li>
33*90c8c64dSAndroid Build Coastguard Worker</ul>
34*90c8c64dSAndroid Build Coastguard Worker
35*90c8c64dSAndroid Build Coastguard Worker<p>Note: Due to browser cache, you need to restart the browser completely before it can recognize
36*90c8c64dSAndroid Build Coastguard Worker any keystore updates.  The easiest way to do this is to dismiss the app in the Recent Apps list.
37*90c8c64dSAndroid Build Coastguard Worker</p>
38*90c8c64dSAndroid Build Coastguard Worker
39*90c8c64dSAndroid Build Coastguard Worker<p>
40*90c8c64dSAndroid Build Coastguard Worker  For more information about using the KeyChain API, see the
41*90c8c64dSAndroid Build Coastguard Worker  <a href="../../../reference/android/security/KeyChain.html">
42*90c8c64dSAndroid Build Coastguard Worker  <code>android.security.KeyChain</code></a>
43*90c8c64dSAndroid Build Coastguard Worker  documentation.
44*90c8c64dSAndroid Build Coastguard Worker</p>
45*90c8c64dSAndroid Build Coastguard Worker
46*90c8c64dSAndroid Build Coastguard Worker<img alt="" src="../images/KeyChainDemo1.png" />
47*90c8c64dSAndroid Build Coastguard Worker<img alt="" src="../images/KeyChainDemo2.png" />
48*90c8c64dSAndroid Build Coastguard Worker<img alt="" src="../images/KeyChainDemo3.png" />
49*90c8c64dSAndroid Build Coastguard Worker<img alt="" src="../images/KeyChainDemo4.png" />
50*90c8c64dSAndroid Build Coastguard Worker
51