Source Code Cross Referenced for PGPOnePassSignature.java in  » Security » Bouncy-Castle » org » bouncycastle » openpgp » 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.openpgp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.bouncycastle.openpgp;
002:
003:        import org.bouncycastle.bcpg.BCPGInputStream;
004:        import org.bouncycastle.bcpg.BCPGOutputStream;
005:        import org.bouncycastle.bcpg.OnePassSignaturePacket;
006:
007:        import java.io.ByteArrayOutputStream;
008:        import java.io.IOException;
009:        import java.io.OutputStream;
010:        import java.security.InvalidKeyException;
011:        import java.security.NoSuchProviderException;
012:        import java.security.Signature;
013:        import java.security.SignatureException;
014:
015:        /**
016:         * A one pass signature object.
017:         */
018:        public class PGPOnePassSignature {
019:            private OnePassSignaturePacket sigPack;
020:            private int signatureType;
021:
022:            private Signature sig;
023:
024:            private byte lastb;
025:
026:            PGPOnePassSignature(BCPGInputStream pIn) throws IOException,
027:                    PGPException {
028:                this ((OnePassSignaturePacket) pIn.readPacket());
029:            }
030:
031:            PGPOnePassSignature(OnePassSignaturePacket sigPack)
032:                    throws PGPException {
033:                this .sigPack = sigPack;
034:                this .signatureType = sigPack.getSignatureType();
035:
036:                try {
037:                    this .sig = Signature.getInstance(PGPUtil.getSignatureName(
038:                            sigPack.getKeyAlgorithm(), sigPack
039:                                    .getHashAlgorithm()), PGPUtil
040:                            .getDefaultProvider());
041:                } catch (Exception e) {
042:                    throw new PGPException("can't set up signature object.", e);
043:                }
044:            }
045:
046:            /**
047:             * Initialise the signature object for verification.
048:             * 
049:             * @param pubKey
050:             * @param provider
051:             * @throws NoSuchProviderException
052:             * @throws PGPException
053:             */
054:            public void initVerify(PGPPublicKey pubKey, String provider)
055:                    throws NoSuchProviderException, PGPException {
056:                lastb = 0;
057:
058:                try {
059:                    sig.initVerify(pubKey.getKey(provider));
060:                } catch (InvalidKeyException e) {
061:                    throw new PGPException("invalid key.", e);
062:                }
063:            }
064:
065:            public void update(byte b) throws SignatureException {
066:                if (signatureType == PGPSignature.CANONICAL_TEXT_DOCUMENT) {
067:                    if (b == '\r') {
068:                        sig.update((byte) '\r');
069:                        sig.update((byte) '\n');
070:                    } else if (b == '\n') {
071:                        if (lastb != '\r') {
072:                            sig.update((byte) '\r');
073:                            sig.update((byte) '\n');
074:                        }
075:                    } else {
076:                        sig.update(b);
077:                    }
078:
079:                    lastb = b;
080:                } else {
081:                    sig.update(b);
082:                }
083:            }
084:
085:            public void update(byte[] bytes) throws SignatureException {
086:                if (signatureType == PGPSignature.CANONICAL_TEXT_DOCUMENT) {
087:                    for (int i = 0; i != bytes.length; i++) {
088:                        this .update(bytes[i]);
089:                    }
090:                } else {
091:                    sig.update(bytes);
092:                }
093:            }
094:
095:            public void update(byte[] bytes, int off, int length)
096:                    throws SignatureException {
097:                if (signatureType == PGPSignature.CANONICAL_TEXT_DOCUMENT) {
098:                    int finish = off + length;
099:
100:                    for (int i = off; i != finish; i++) {
101:                        this .update(bytes[i]);
102:                    }
103:                } else {
104:                    sig.update(bytes, off, length);
105:                }
106:            }
107:
108:            /**
109:             * Verify the calculated signature against the passed in PGPSignature.
110:             * 
111:             * @param pgpSig
112:             * @return boolean
113:             * @throws PGPException
114:             * @throws SignatureException
115:             */
116:            public boolean verify(PGPSignature pgpSig) throws PGPException,
117:                    SignatureException {
118:                sig.update(pgpSig.getSignatureTrailer());
119:
120:                return sig.verify(pgpSig.getSignature());
121:            }
122:
123:            public long getKeyID() {
124:                return sigPack.getKeyID();
125:            }
126:
127:            public int getSignatureType() {
128:                return sigPack.getSignatureType();
129:            }
130:
131:            public int getHashAlgorithm() {
132:                return sigPack.getHashAlgorithm();
133:            }
134:
135:            public int getKeyAlgorithm() {
136:                return sigPack.getKeyAlgorithm();
137:            }
138:
139:            public byte[] getEncoded() throws IOException {
140:                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
141:
142:                this .encode(bOut);
143:
144:                return bOut.toByteArray();
145:            }
146:
147:            public void encode(OutputStream outStream) throws IOException {
148:                BCPGOutputStream out;
149:
150:                if (outStream instanceof  BCPGOutputStream) {
151:                    out = (BCPGOutputStream) outStream;
152:                } else {
153:                    out = new BCPGOutputStream(outStream);
154:                }
155:
156:                out.writePacket(sigPack);
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.