Source Code Cross Referenced for SHA224HMacTest.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) 


01:        package org.bouncycastle.crypto.test;
02:
03:        import org.bouncycastle.crypto.digests.SHA224Digest;
04:        import org.bouncycastle.crypto.macs.HMac;
05:        import org.bouncycastle.crypto.params.KeyParameter;
06:        import org.bouncycastle.util.Arrays;
07:        import org.bouncycastle.util.encoders.Hex;
08:        import org.bouncycastle.util.test.SimpleTestResult;
09:        import org.bouncycastle.util.test.Test;
10:        import org.bouncycastle.util.test.TestResult;
11:
12:        /**
13:         * SHA224 HMac Test
14:         */
15:        public class SHA224HMacTest implements  Test {
16:            final static String[] keys = {
17:                    "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
18:                    "4a656665",
19:                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20:                    "0102030405060708090a0b0c0d0e0f10111213141516171819",
21:                    "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c",
22:                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
23:                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" };
24:
25:            final static String[] digests = {
26:                    "896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22",
27:                    "a30e01098bc6dbbf45690f3a7e9e6d0f8bbea2a39e6148008fd05e44",
28:                    "7fb3cb3588c6c1f6ffa9694d7d6ad2649365b0c1f65d69d1ec8333ea",
29:                    "6c11506874013cac6a2abc1bb382627cec6a90d86efc012de7afec5a",
30:                    "0e2aea68a90c8d37c988bcdb9fca6fa8099cd857c7ec4a1815cac54c",
31:                    "95e9a0db962095adaebe9b2d6f0dbce2d499f112f2d2b7273fa6870e",
32:                    "3a854166ac5d9f023f54d517d0b39dbd946770db9c2b95c9f6f565d1" };
33:
34:            final static String[] messages = {
35:                    "Hi There",
36:                    "what do ya want for nothing?",
37:                    "0xdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
38:                    "0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
39:                    "Test With Truncation",
40:                    "Test Using Larger Than Block-Size Key - Hash Key First",
41:                    "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." };
42:
43:            public String getName() {
44:                return "SHA224HMac";
45:            }
46:
47:            public TestResult perform() {
48:                HMac hmac = new HMac(new SHA224Digest());
49:                byte[] resBuf = new byte[hmac.getMacSize()];
50:
51:                for (int i = 0; i < messages.length; i++) {
52:                    byte[] m = messages[i].getBytes();
53:                    if (messages[i].startsWith("0x")) {
54:                        m = Hex.decode(messages[i].substring(2));
55:                    }
56:                    hmac.init(new KeyParameter(Hex.decode(keys[i])));
57:                    hmac.update(m, 0, m.length);
58:                    hmac.doFinal(resBuf, 0);
59:
60:                    if (!Arrays.areEqual(resBuf, Hex.decode(digests[i]))) {
61:                        return new SimpleTestResult(false, getName()
62:                                + ": Vector " + i + " failed got -"
63:                                + new String(Hex.encode(resBuf)));
64:                    }
65:                }
66:
67:                //
68:                // test reset
69:                //
70:                int vector = 0; // vector used for test
71:                byte[] m = messages[vector].getBytes();
72:                if (messages[vector].startsWith("0x")) {
73:                    m = Hex.decode(messages[vector].substring(2));
74:                }
75:                hmac.init(new KeyParameter(Hex.decode(keys[vector])));
76:                hmac.update(m, 0, m.length);
77:                hmac.doFinal(resBuf, 0);
78:                hmac.reset();
79:                hmac.update(m, 0, m.length);
80:                hmac.doFinal(resBuf, 0);
81:
82:                if (!Arrays.areEqual(resBuf, Hex.decode(digests[vector]))) {
83:                    return new SimpleTestResult(false, getName()
84:                            + "Reset with vector " + vector + " failed");
85:                }
86:
87:                return new SimpleTestResult(true, getName() + ": Okay");
88:            }
89:
90:            public static void main(String[] args) {
91:                SHA224HMacTest test = new SHA224HMacTest();
92:                TestResult result = test.perform();
93:
94:                System.out.println(result);
95:            }
96:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.