• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.bouncycastle.jcajce.provider.digest;
2 
3 import org.bouncycastle.asn1.iana.IANAObjectIdentifiers;
4 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
5 import org.bouncycastle.crypto.CipherKeyGenerator;
6 import org.bouncycastle.crypto.digests.MD5Digest;
7 import org.bouncycastle.crypto.macs.HMac;
8 import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
9 import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
10 import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
11 
12 public class MD5
13 {
MD5()14     private MD5()
15     {
16 
17     }
18 
19     /**
20      * MD5 HashMac
21      */
22     public static class HashMac
23         extends BaseMac
24     {
HashMac()25         public HashMac()
26         {
27             super(new HMac(new MD5Digest()));
28         }
29     }
30 
31     public static class KeyGenerator
32         extends BaseKeyGenerator
33     {
KeyGenerator()34         public KeyGenerator()
35         {
36             super("HMACMD5", 128, new CipherKeyGenerator());
37         }
38     }
39 
40     static public class Digest
41         extends BCMessageDigest
42         implements Cloneable
43     {
Digest()44         public Digest()
45         {
46             super(new MD5Digest());
47         }
48 
clone()49         public Object clone()
50             throws CloneNotSupportedException
51         {
52             Digest d = (Digest)super.clone();
53             d.digest = new MD5Digest((MD5Digest)digest);
54 
55             return d;
56         }
57     }
58 
59     public static class Mappings
60         extends DigestAlgorithmProvider
61     {
62         private static final String PREFIX = MD5.class.getName();
63 
Mappings()64         public Mappings()
65         {
66         }
67 
configure(ConfigurableProvider provider)68         public void configure(ConfigurableProvider provider)
69         {
70             provider.addAlgorithm("MessageDigest.MD5", PREFIX + "$Digest");
71             provider.addAlgorithm("Alg.Alias.MessageDigest." + PKCSObjectIdentifiers.md5, "MD5");
72 
73             addHMACAlgorithm(provider, "MD5", PREFIX + "$HashMac", PREFIX + "$KeyGenerator");
74             addHMACAlias(provider, "MD5", IANAObjectIdentifiers.hmacMD5);
75         }
76     }
77 }
78