Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / test / JU_KeyMarshaling.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.cm.test;
23
24 import java.io.IOException;
25 import java.security.KeyPair;
26 import java.security.PrivateKey;
27 import java.security.PublicKey;
28
29 import org.junit.AfterClass;
30 import org.junit.Test;
31 import org.onap.aaf.auth.env.AuthzEnv;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.cadi.cm.CertException;
34 import org.onap.aaf.cadi.cm.Factory;
35
36 import junit.framework.Assert;
37
38 public class JU_KeyMarshaling {
39
40         @AfterClass
41         public static void tearDownAfterClass() throws Exception {
42         }
43
44         @Test
45         public void test() {
46                 AuthzEnv env = new AuthzEnv();
47                 AuthzTrans trans = env.newTrans();
48                 try {
49                         KeyPair kpair = Factory.generateKeyPair(trans);
50                         String privateString = Factory.toString(trans, kpair.getPrivate());
51                         System.out.println("Private as base64 encoded as PKCS8 Spec");
52                         System.out.println(privateString);
53                         
54                         // Take String, and create Private Key
55                         PrivateKey pk = Factory.toPrivateKey(trans, privateString);
56                         Assert.assertEquals(kpair.getPrivate().getAlgorithm(), pk.getAlgorithm());
57                         Assert.assertEquals(kpair.getPrivate().getFormat(), pk.getFormat());
58                         Assert.assertEquals(kpair.getPrivate().getEncoded(), pk.getEncoded());
59                 
60                         
61                         String s = Factory.toString(trans, kpair.getPublic());
62                         System.out.println("Public as base64 encoded x509 Spec");
63                         System.out.println(s);
64                         
65                         PublicKey pub = Factory.toPublicKey(trans, s);
66                         Assert.assertEquals(kpair.getPublic().toString(), pub.toString());
67                         
68                         
69                 } catch (IOException e) {
70                         e.printStackTrace();
71                 } catch (CertException e) {
72                         e.printStackTrace();
73                 } finally {
74                         StringBuilder sb = new StringBuilder("=== Timings ===\n");
75                         trans.auditTrail(1, sb);
76                         System.out.println(sb);
77                 }
78         }
79
80 }