我正在使用Java实现C#SignedCms功能.
我正在使用bouncycastle libs.问题是我得到的java签名与使用SignedCms生成的签名不同.
X509Certificate2 certificate = new X509Certificate2("myCertPath", "myPass");
String text = "text";
ContentInfo contentInfo = new ContentInfo(System.Text.Encoding.UTF8.GetBytes(text));
SignedCms cms = new SignedCms(contentInfo, false);
CmsSigner signer = new CmsSigner(certificate);
signer.IncludeOption = X509IncludeOption.None;
signer.DigestAlgorithm = new Oid("SHA1");
cms.ComputeSignature(signer, false);
byte[] signature = cms.Encode();
print(signature);
Run Code Online (Sandbox Code Playgroud)
Security.addProvider(new BouncyCastleProvider());
char[] password = "myPass".toCharArray();
String text = "text";
FileInputStream fis = new FileInputStream("myCertPath");
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(fis, password);
String alias = ks.aliases().nextElement();
PrivateKey pKey = (PrivateKey)ks.getKey(alias, password);
X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
java.util.List …Run Code Online (Sandbox Code Playgroud) 有很多次问过类似的问题.但是我仍然不明白为什么在用ICC_Profile转换图片后输出太暗.我尝试了很多配置文件:来自Adobe网站,以及图片本身.
在图像之前

图像之后

码
Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader reader = null;
while (readers.hasNext()){
reader = readers.next();
if (reader.canReadRaster()){
break;
}
}
// read
ImageInputStream ios = ImageIO.createImageInputStream(new FileInputStream(new File(myPic.jpg)));
reader.setInput(ios);
Raster r = reader.readRaster(0, null);
BufferedImage result = new BufferedImage(r.getWidth(), r.getHeight(), bufferedImage.TYPE_INT_RGB);
WritableRaster resultRaster = result.getRaster();
ICC_Profile iccProfile = ICC_Profile.getInstance(new File("profile_name.icc");
ColorSpace cs = new ICC_ColorSpace(iccProfile);
ColorConvertOp cmykToRgb = new ColorConvertOp(cs, result.getColorModel().getColorSpace(), null);
cmykToRgb.filter(r, resultRaster);
// write
ImageIo.write(resul, "jpg", new File("myPic.jpg"));
Run Code Online (Sandbox Code Playgroud)
转换图片后,我还需要做些什么吗?
我在.Net项目中使用BigInteger的单声道实现(链接)在Java中我使用java.math.BigInteger.
相同的代码在Java中产生不同的结果.
.Net代码
String inputBytes = "8E5BD77F0DCC30864634C134E28BFB42A149675A320786B616F4530708350D270353C30A40450325801B7AFED12BCCA274B8187072A89CC0CC3F95A24A8251243C1835898246F4D64CA3AC61DB841518F0E8FBC8996A40EB626153AE7F0BB87FD713FAC522719431428DE178E780A3FA45788A72C431926AED990E6DA268D2CC";
String modulus = "00e6b4b4511e0bd1b3d9c82ee189ba6d0c70b1466d94126f99a741af99a92701a789451742a357ddb61a4dea409965ec58dcaa5e30826de871b04700ed0fd46b1693446049734e8f95faba2bf9301347e63ba1771650e71982adef0cca6890b6f7baa7f5421a6533652f4b70c3c4270c480cf54cc06635f22901a42716d1dadf4f";
String exp = "010001";
BigInteger mModulus = new BigInteger(hexStringToByteArray(modulus));
BigInteger mExponent = new BigInteger(hexStringToByteArray(exp));
BigInteger input = new BigInteger(hexStringToByteArray(inputBytes));
BigInteger output = input.ModPow(mExponent, mModulus);
Console.WriteLine("==RESULT==" + byteArray2Hex(output.GetBytes()));
public static byte[] hexStringToByteArray(string hexString)
{
if (hexString.Length % 2 != 0)
throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString));
byte[] HexAsBytes = new byte[hexString.Length / 2];
for (int index = 0; index …Run Code Online (Sandbox Code Playgroud) 我使用ASM基于类生成超类ToOverride.我想覆盖它的ToOverride::getValue方法.上面提到的类看起来像:
public abstract class ToOverride {
Object getValue(String str, Object arg) throws Exception {
throw new IllegalStateException("PARENT!");
}
Object justMethod() {
return "test";
}
}
Run Code Online (Sandbox Code Playgroud)
在普通的java中,期望的类看起来像这样:
public class GeneratedInheritor extends ToOverride {
@Override
Object getValue(String str, Object arg) throws Exception {
return str + arg;
}
}
Run Code Online (Sandbox Code Playgroud)
我生成了后一个类,导致后面的字节码.
// class version 49.0 (49)
// access flags 0x21
public class com/example/GeneratedInheritor extends com/example/ToOverride {
// access flags 0x1
public <init>()V
ALOAD 0
INVOKESPECIAL com/example/ToOverride.<init> ()V
RETURN
MAXSTACK …Run Code Online (Sandbox Code Playgroud) java ×4
.net ×1
asn.1 ×1
biginteger ×1
bouncycastle ×1
c# ×1
classloader ×1
cmyk ×1
overriding ×1