APIdia Launch Partner
Top Description Fields Constructors Methods
sun.security.pkcs12

pack-priv Class MacData

extends Object
Class Inheritance
Imports
java.io.IOException, java.security.*, java.security.spec.InvalidKeySpecException, javax.crypto.Mac, .SecretKey, .SecretKeyFactory, javax.crypto.spec.PBEKeySpec, .PBEParameterSpec, sun.security.pkcs.ParsingException, sun.security.util.*, sun.security.x509.AlgorithmId

The MacData type, as defined in PKCS#12. The ASN.1 definition is as follows:

MacData ::= SEQUENCE {
    mac        DigestInfo,
    macSalt    OCTET STRING,
    iterations INTEGER DEFAULT 1
     -- Note: The default is for historical reasons and its use is
     -- deprecated.
}

DigestInfo ::= SEQUENCE {
    digestAlgorithm DigestAlgorithmIdentifier,
    digest OCTET STRING
}

Author
Sharon Liu

Field Summary

Modifier and TypeField and Description
private static final Debug
private final byte[]
private final String
private final int
private final String
private final int
private final String
private final byte[]

Constructor Summary

AccessConstructor and Description
pack-priv
MacData(DerInputStream derin)

Parses a PKCS#12 MAC data.

Method Summary

Modifier and TypeMethod and Description
private static byte[]

Returns:

the computed MAC as a byte array
calculateMac
(String
the algorithm used to compute the MAC
macAlgorithm
,
char[]
the password used to generate the key
password
,
PBEParameterSpec
a PBEParameterSpec object
params
,
byte[]
the data on which the MAC is computed
data
,
String
the pseudorandom function used to compute the key for PBMAC1
kdfHmac
,
String
the algorithm used to compute the MAC
hmac
,
int
the length of the key generated by the pseudorandom function
keyLength
)

Computes a MAC on the data.

pack-priv static byte[]

Returns:

the ASN.1 encoding
encode
(String algName, byte[] digest, PBEParameterSpec p, String kdfHmac, String hmac, int keyLength)

Returns the ASN.1 encoding.

pack-priv static byte[]
generateMac(char[] passwd, byte[] data, String macAlgorithm, int macIterationCount, byte[] salt)

pack-priv int
pack-priv String
private static String
private static String
pack-priv void
verifyMac(char[]
the password used to generate the key
password
,
byte[]
the data on which the MAC is computed
data
)

Verify Mac on the data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
private static final Debug debug
digestback to summary
private final byte[] digest
hmacback to summary
private final String hmac
iterationsback to summary
private final int iterations
kdfHmacback to summary
private final String kdfHmac
keyLengthback to summary
private final int keyLength
macAlgorithmback to summary
private final String macAlgorithm
macSaltback to summary
private final byte[] macSalt

Constructor Detail

MacDataback to summary
pack-priv MacData(DerInputStream derin) throws IOException

Parses a PKCS#12 MAC data.

Method Detail

calculateMacback to summary
private static byte[] calculateMac(String macAlgorithm, char[] password, PBEParameterSpec params, byte[] data, String kdfHmac, String hmac, int keyLength) throws InvalidAlgorithmParameterException, InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException

Computes a MAC on the data. This is a two-step process: first generate a key and then use the key to generate the MAC. PBMAC1 and non-PBMAC1 keys use different key factories. PBMAC1 uses a pseudorandom function (kdfHmac) to generate keys while non-PBMAC1 does not. The MAC is computed according to the specified hmac algorithm.

Parameters
macAlgorithm:String

the algorithm used to compute the MAC

password:char[]

the password used to generate the key

params:PBEParameterSpec

a PBEParameterSpec object

data:byte[]

the data on which the MAC is computed

kdfHmac:String

the pseudorandom function used to compute the key for PBMAC1

hmac:String

the algorithm used to compute the MAC

keyLength:int

the length of the key generated by the pseudorandom function

Returns:byte[]

the computed MAC as a byte array

Exceptions
NoSuchAlgorithmException:
if either kdfHmac or hmac is unknown to the Mac or SecretKeyFactory
encodeback to summary
pack-priv static byte[] encode(String algName, byte[] digest, PBEParameterSpec p, String kdfHmac, String hmac, int keyLength) throws IOException, NoSuchAlgorithmException

Returns the ASN.1 encoding.

Returns:byte[]

the ASN.1 encoding

Exceptions
NoSuchAlgorithmException:
if error occurs when constructing its ASN.1 encoding.
generateMacback to summary
pack-priv static byte[] generateMac(char[] passwd, byte[] data, String macAlgorithm, int macIterationCount, byte[] salt) throws IOException, NoSuchAlgorithmException
getIterationsback to summary
pack-priv int getIterations()
getMacAlgorithmback to summary
pack-priv String getMacAlgorithm()
parseHmacback to summary
private static String parseHmac(String text)
parseKdfHmacback to summary
private static String parseKdfHmac(String text)
verifyMacback to summary
pack-priv void verifyMac(char[] password, byte[] data) throws InvalidAlgorithmParameterException, InvalidKeyException, InvalidKeySpecException, NoSuchAlgorithmException, UnrecoverableKeyException

Verify Mac on the data. Calculate Mac on the data and compare with Mac found in input stream.

Parameters
password:char[]

the password used to generate the key

data:byte[]

the data on which the MAC is computed

Exceptions
UnrecoverableKeyException:
if calculated Mac and Mac found in input stream are different