本文整理汇总了Java中javax.crypto.MacSpi类的典型用法代码示例。如果您正苦于以下问题:Java MacSpi类的具体用法?Java MacSpi怎么用?Java MacSpi使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MacSpi类属于javax.crypto包,在下文中一共展示了MacSpi类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetMacLength
import javax.crypto.MacSpi; //导入依赖的package包/类
/**
* Test for <code>getMacLength()</code> method
* Assertion: return Mac length
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "getMacLength",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = MacSpi.class,
method = "engineGetMacLength",
args = {}
)
})
public void testGetMacLength() {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
Mac [] macs = createMacs();
assertNotNull("Mac objects were not created", macs);
for (int i = 0; i < macs.length; i++) {
assertTrue("Length should be positive", (macs[i].getMacLength() >= 0));
}
}
示例2: create
import javax.crypto.MacSpi; //导入依赖的package包/类
public MacSpi create(Object constructorParam) {
try {
return Adaptor.adapt(type.newInstance(), MacSpi.class);
} catch (Exception e) {
throw new IllegalArgumentException("Invalid type: " + type, e);
}
}
示例3: doFinal
import javax.crypto.MacSpi; //导入依赖的package包/类
/**
* Test for <code>doFinal(byte[] output, int outOffset)</code> and
* <code>doFinal()</code> methods Assertion: Mac result is stored in
* output buffer
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Checks functionality.",
method = "doFinal",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Checks IllegalStateException only but for all methods. Not enough for doFinal(byte[] output, int outOffset) - it can throw ShortBufferException",
clazz = MacSpi.class,
method = "engineDoFinal",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Checks functionality.",
method = "doFinal",
args = {byte[].class, int.class}
)
})
public void testMac11() throws NoSuchAlgorithmException, NoSuchProviderException,
IllegalArgumentException, IllegalStateException,
InvalidKeyException, ShortBufferException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
Mac [] macs = createMacs();
assertNotNull("Mac objects were not created", macs);
byte [] b = {(byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
SecretKeySpec scs = new SecretKeySpec(b, "SHA1");
for (int i = 0; i < macs.length; i++) {
macs[i].init(scs);
byte [] res1 = macs[i].doFinal();
byte [] res2 = new byte[res1.length + 10];
macs[i].doFinal(res2, 0);
for (int j = 0; j < res1.length; j++) {
assertEquals("Not equals byte number: "
.concat(Integer.toString(j)), res1[j], res2[j]);
}
}
}
示例4: testReset
import javax.crypto.MacSpi; //导入依赖的package包/类
/**
* Test for <code>reset()</code> method
* Assertion: return Mac length
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "reset",
args = {}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
clazz = MacSpi.class,
method = "engineReset",
args = {}
)
})
public void testReset() throws InvalidKeyException {
if (!DEFSupported) {
fail(NotSupportedMsg);
return;
}
Mac [] macs = createMacs();
assertNotNull("Mac objects were not created", macs);
byte [] bb = {(byte)1, (byte)2, (byte)3, (byte)4, (byte)5};
SecretKeySpec sks = new SecretKeySpec(bb, "SHA1");
byte [] bbuf = {(byte)5, (byte)4, (byte)3, (byte)2, (byte)1};
byte [] bb1;
byte [] bb2;
for (int i = 0; i < macs.length; i++) {
macs[i].init(sks);
bb1 = macs[i].doFinal();
macs[i].reset();
bb2 = macs[i].doFinal();
assertEquals("incorrect result",bb1.length, bb2.length);
for (int t = 0; t < bb1.length; t++) {
assertEquals("Incorrect doFinal result", bb1[t], bb2[t]);
}
macs[i].reset();
macs[i].update(bbuf);
bb1 = macs[i].doFinal();
macs[i].reset();
macs[i].update(bbuf, 0, bbuf.length);
bb2 = macs[i].doFinal();
assertEquals("incorrect result",bb1.length, bb2.length);
for (int t = 0; t < bb1.length; t++) {
assertEquals("Incorrect doFinal result", bb1[t], bb2[t]);
}
}
}
示例5: Mock_Mac
import javax.crypto.MacSpi; //导入依赖的package包/类
protected Mock_Mac(MacSpi arg0, Provider arg1, String arg2) {
super(arg0, arg1, arg2);
}
示例6: myMac
import javax.crypto.MacSpi; //导入依赖的package包/类
public myMac(MacSpi macSpi, Provider provider,
String algorithm) {
super(macSpi, provider, algorithm);
}
示例7: MacSpiFactory
import javax.crypto.MacSpi; //导入依赖的package包/类
public MacSpiFactory(Class<? extends javax.crypto.MacSpi> type) {
this.type = type;
}
示例8: Mac
import javax.crypto.MacSpi; //导入依赖的package包/类
/** @ar.org.fitc.spec_ref */
protected Mac(MacSpi macSpi, Provider provider, String algorithm) {
this.macSpi = macSpi;
this.provider = provider;
this.algorithm = algorithm;
}
示例9: clone
import javax.crypto.MacSpi; //导入依赖的package包/类
/** @ar.org.fitc.spec_ref */
public final Object clone() throws CloneNotSupportedException {
return new Mac((MacSpi) macSpi.clone(), provider, algorithm);
}
示例10: newInstance
import javax.crypto.MacSpi; //导入依赖的package包/类
/**
* It's used as a factory method
*
* @param algorithm
* the algorithm
* @param provider
* the provider
* @return A new Mac object
* @throws NoSuchAlgorithmException
* If the specified algorithm is not available in the default
* package or any of the others providers that were searched
*/
private static final Mac newInstance(String algorithm, Provider provider)
throws NoSuchAlgorithmException {
Service service = Util.getService(Types.MAC, algorithm, provider);
if (service == null) {
throw new NoSuchAlgorithmException("No such algorithm: "
+ algorithm);
}
return new Mac((MacSpi) service.newInstance(null),
service.getProvider(), algorithm);
}