use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.
the class CCMParameters method toASN1Primitive.
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector v = new ASN1EncodableVector(2);
v.add(new DEROctetString(nonce));
if (icvLen != 12) {
v.add(new ASN1Integer(icvLen));
}
return new DERSequence(v);
}
use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.
the class SignatureSpiLe method engineSign.
protected byte[] engineSign() throws SignatureException {
byte[] signature = ASN1OctetString.getInstance(super.engineSign()).getOctets();
reverseBytes(signature);
try {
return (new DEROctetString(signature)).getEncoded();
} catch (Exception e) {
throw new SignatureException(e.toString());
}
}
use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.
the class SignatureSpi method engineSign.
protected byte[] engineSign() throws SignatureException {
byte[] hash = new byte[digest.getDigestSize()];
digest.doFinal(hash, 0);
try {
BigInteger[] sig = signer.generateSignature(hash);
byte[] r = sig[0].toByteArray();
byte[] s = sig[1].toByteArray();
byte[] sigBytes = new byte[(r.length > s.length ? r.length * 2 : s.length * 2)];
System.arraycopy(s, 0, sigBytes, (sigBytes.length / 2) - s.length, s.length);
System.arraycopy(r, 0, sigBytes, sigBytes.length - r.length, r.length);
return new DEROctetString(sigBytes).getEncoded();
} catch (Exception e) {
throw new SignatureException(e.toString());
}
}
use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.
the class BCDSTU4145PublicKey method getEncoded.
public byte[] getEncoded() {
ASN1Encodable params;
SubjectPublicKeyInfo info;
if (dstuParams != null) {
params = dstuParams;
} else {
if (ecSpec instanceof ECNamedCurveSpec) {
params = new DSTU4145Params(new ASN1ObjectIdentifier(((ECNamedCurveSpec) ecSpec).getName()));
} else {
// strictly speaking this may not be applicable...
ECCurve curve = EC5Util.convertCurve(ecSpec.getCurve());
X9ECParameters ecP = new X9ECParameters(curve, new X9ECPoint(EC5Util.convertPoint(curve, ecSpec.getGenerator()), withCompression), ecSpec.getOrder(), BigInteger.valueOf(ecSpec.getCofactor()), ecSpec.getCurve().getSeed());
params = new X962Parameters(ecP);
}
}
// NOTE: 'withCompression' is ignored here
byte[] encKey = DSTU4145PointEncoder.encodePoint(ecPublicKey.getQ());
try {
info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(UAObjectIdentifiers.dstu4145be, params), new DEROctetString(encKey));
} catch (IOException e) {
return null;
}
return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
}
use of com.github.zhenwei.core.asn1.DEROctetString in project LinLong-Java by zhenwei1108.
the class SspRange method getInstance.
public static SspRange getInstance(Object src) {
if (src instanceof SspRange) {
return (SspRange) src;
}
ASN1TaggedObject taggedObject = ASN1TaggedObject.getInstance(src);
int item = taggedObject.getTagNo();
switch(item) {
case opaque:
return new SspRange(opaque, SequenceOfOctetString.getInstance(taggedObject.getObject()));
case all:
return new SspRange(all, DERNull.INSTANCE);
case extension:
try {
return new SspRange(extension, new DEROctetString(taggedObject.getObject().getEncoded()));
} catch (IOException ioException) {
throw new RuntimeException(ioException.getMessage(), ioException);
}
case bitmapSspRange:
return new SspRange(bitmapSspRange, BitmapSspRange.getInstance(taggedObject.getObject()));
}
throw new IllegalStateException("unknown choice " + item);
}
Aggregations