~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to src/org/bouncycastle/cert/crmf/PKMACValueGenerator.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.cert.crmf;
 
2
 
 
3
import java.io.IOException;
 
4
import java.io.OutputStream;
 
5
 
 
6
import org.bouncycastle.asn1.DERBitString;
 
7
import org.bouncycastle.asn1.crmf.PKMACValue;
 
8
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
 
9
import org.bouncycastle.operator.MacCalculator;
 
10
 
 
11
class PKMACValueGenerator
 
12
{
 
13
    private PKMACBuilder builder;
 
14
 
 
15
    public PKMACValueGenerator(PKMACBuilder builder)
 
16
    {
 
17
        this.builder = builder;
 
18
    }
 
19
 
 
20
    public PKMACValue generate(char[] password, SubjectPublicKeyInfo keyInfo)
 
21
        throws CRMFException
 
22
    {
 
23
        MacCalculator calculator = builder.build(password);
 
24
 
 
25
        OutputStream macOut = calculator.getOutputStream();
 
26
 
 
27
        try
 
28
        {
 
29
            macOut.write(keyInfo.getDEREncoded());
 
30
 
 
31
            macOut.close();
 
32
        }
 
33
        catch (IOException e)
 
34
        {
 
35
            throw new CRMFException("exception encoding mac input: " + e.getMessage(), e);
 
36
        }
 
37
 
 
38
        return new PKMACValue(calculator.getAlgorithmIdentifier(), new DERBitString(calculator.getMac()));
 
39
    }
 
40
}