Source Code Cross Referenced for AESWrapTest.java in  » Security » Bouncy-Castle » org » bouncycastle » crypto » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » Bouncy Castle » org.bouncycastle.crypto.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.crypto.test;
002:
003:        import org.bouncycastle.crypto.DataLengthException;
004:        import org.bouncycastle.crypto.InvalidCipherTextException;
005:        import org.bouncycastle.crypto.Wrapper;
006:        import org.bouncycastle.crypto.engines.AESWrapEngine;
007:        import org.bouncycastle.crypto.params.KeyParameter;
008:        import org.bouncycastle.util.Arrays;
009:        import org.bouncycastle.util.encoders.Hex;
010:        import org.bouncycastle.util.test.SimpleTestResult;
011:        import org.bouncycastle.util.test.Test;
012:        import org.bouncycastle.util.test.TestResult;
013:
014:        /**
015:         * Wrap Test
016:         */
017:        public class AESWrapTest implements  Test {
018:            public String getName() {
019:                return "AESWrap";
020:            }
021:
022:            private TestResult wrapTest(int id, byte[] kek, byte[] in,
023:                    byte[] out) {
024:                Wrapper wrapper = new AESWrapEngine();
025:
026:                wrapper.init(true, new KeyParameter(kek));
027:
028:                try {
029:                    byte[] cText = wrapper.wrap(in, 0, in.length);
030:                    if (!Arrays.areEqual(cText, out)) {
031:                        return new SimpleTestResult(false, getName()
032:                                + ": failed wrap test " + id + " expected "
033:                                + new String(Hex.encode(out)) + " got "
034:                                + new String(Hex.encode(cText)));
035:                    }
036:                } catch (Exception e) {
037:                    return new SimpleTestResult(false, getName()
038:                            + ": failed wrap test exception " + e.toString());
039:                }
040:
041:                wrapper.init(false, new KeyParameter(kek));
042:
043:                try {
044:                    byte[] pText = wrapper.unwrap(out, 0, out.length);
045:                    if (!Arrays.areEqual(pText, in)) {
046:                        return new SimpleTestResult(false, getName()
047:                                + ": failed unwrap test " + id + " expected "
048:                                + new String(Hex.encode(in)) + " got "
049:                                + new String(Hex.encode(pText)));
050:                    }
051:                } catch (Exception e) {
052:                    return new SimpleTestResult(false, getName()
053:                            + ": failed unwrap test exception.", e);
054:                }
055:
056:                return new SimpleTestResult(true, getName() + ": Okay");
057:            }
058:
059:            public TestResult perform() {
060:                byte[] kek1 = Hex.decode("000102030405060708090a0b0c0d0e0f");
061:                byte[] in1 = Hex.decode("00112233445566778899aabbccddeeff");
062:                byte[] out1 = Hex
063:                        .decode("1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5");
064:                TestResult result = wrapTest(1, kek1, in1, out1);
065:
066:                if (!result.isSuccessful()) {
067:                    return result;
068:                }
069:
070:                byte[] kek2 = Hex
071:                        .decode("000102030405060708090a0b0c0d0e0f1011121314151617");
072:                byte[] in2 = Hex.decode("00112233445566778899aabbccddeeff");
073:                byte[] out2 = Hex
074:                        .decode("96778b25ae6ca435f92b5b97c050aed2468ab8a17ad84e5d");
075:                result = wrapTest(2, kek2, in2, out2);
076:                if (!result.isSuccessful()) {
077:                    return result;
078:                }
079:
080:                byte[] kek3 = Hex
081:                        .decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
082:                byte[] in3 = Hex.decode("00112233445566778899aabbccddeeff");
083:                byte[] out3 = Hex
084:                        .decode("64e8c3f9ce0f5ba263e9777905818a2a93c8191e7d6e8ae7");
085:                result = wrapTest(3, kek3, in3, out3);
086:                if (!result.isSuccessful()) {
087:                    return result;
088:                }
089:
090:                byte[] kek4 = Hex
091:                        .decode("000102030405060708090a0b0c0d0e0f1011121314151617");
092:                byte[] in4 = Hex
093:                        .decode("00112233445566778899aabbccddeeff0001020304050607");
094:                byte[] out4 = Hex
095:                        .decode("031d33264e15d33268f24ec260743edce1c6c7ddee725a936ba814915c6762d2");
096:                result = wrapTest(4, kek4, in4, out4);
097:                if (!result.isSuccessful()) {
098:                    return result;
099:                }
100:
101:                byte[] kek5 = Hex
102:                        .decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
103:                byte[] in5 = Hex
104:                        .decode("00112233445566778899aabbccddeeff0001020304050607");
105:                byte[] out5 = Hex
106:                        .decode("a8f9bc1612c68b3ff6e6f4fbe30e71e4769c8b80a32cb8958cd5d17d6b254da1");
107:                result = wrapTest(5, kek5, in5, out5);
108:                if (!result.isSuccessful()) {
109:                    return result;
110:                }
111:
112:                byte[] kek6 = Hex
113:                        .decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f");
114:                byte[] in6 = Hex
115:                        .decode("00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f");
116:                byte[] out6 = Hex
117:                        .decode("28c9f404c4b810f4cbccb35cfb87f8263f5786e2d80ed326cbc7f0e71a99f43bfb988b9b7a02dd21");
118:                result = wrapTest(6, kek6, in6, out6);
119:                if (!result.isSuccessful()) {
120:                    return result;
121:                }
122:
123:                Wrapper wrapper = new AESWrapEngine();
124:                KeyParameter key = new KeyParameter(new byte[16]);
125:                byte[] buf = new byte[16];
126:
127:                try {
128:                    wrapper.init(true, key);
129:
130:                    wrapper.unwrap(buf, 0, buf.length);
131:
132:                    return new SimpleTestResult(false, getName()
133:                            + ": failed unwrap state test.");
134:                } catch (IllegalStateException e) {
135:                    // expected
136:                } catch (InvalidCipherTextException e) {
137:                    return new SimpleTestResult(false, getName()
138:                            + ": unexpected exception: " + e, e);
139:                }
140:
141:                try {
142:                    wrapper.init(false, key);
143:
144:                    wrapper.wrap(buf, 0, buf.length);
145:
146:                    return new SimpleTestResult(false, getName()
147:                            + ": failed unwrap state test.");
148:                } catch (IllegalStateException e) {
149:                    // expected
150:                }
151:
152:                //
153:                // short test
154:                //
155:                try {
156:                    wrapper.init(false, key);
157:
158:                    wrapper.unwrap(buf, 0, buf.length / 2);
159:
160:                    return new SimpleTestResult(false, getName()
161:                            + ": failed unwrap short test.");
162:                } catch (InvalidCipherTextException e) {
163:                    // expected
164:                }
165:
166:                try {
167:                    wrapper.init(true, key);
168:
169:                    wrapper.wrap(buf, 0, 15);
170:
171:                    return new SimpleTestResult(false, getName()
172:                            + ": failed wrap length test.");
173:                } catch (DataLengthException e) {
174:                    // expected
175:                }
176:
177:                return new SimpleTestResult(true, getName() + ": Okay");
178:            }
179:
180:            public static void main(String[] args) {
181:                AESWrapTest test = new AESWrapTest();
182:                TestResult result = test.perform();
183:
184:                System.out.println(result);
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.