48 lines
1.1 KiB
Java
48 lines
1.1 KiB
Java
package com.chakracoin.shsm.cert;
|
|
|
|
|
|
import com.sunyard.ssp.BytesUtil;
|
|
|
|
import java.security.PublicKey;
|
|
|
|
public class SimplePublicKey implements PublicKey {
|
|
|
|
private byte[] encoded;
|
|
|
|
public SimplePublicKey(String str) {
|
|
this.encoded = BytesUtil.hexString2Bytes( str );
|
|
}
|
|
|
|
@Override
|
|
public String getAlgorithm() {
|
|
return "EC";
|
|
}
|
|
|
|
@Override
|
|
public String getFormat() {
|
|
return "PKCS#8";
|
|
}
|
|
|
|
@Override
|
|
public byte[] getEncoded() {
|
|
return this.encoded;
|
|
}
|
|
|
|
|
|
public static SimplePublicKey getSimplePublickKey(String der) {
|
|
|
|
if (null == der || !der.startsWith("03420004") ) {
|
|
throw new IllegalArgumentException("公钥格式错误");
|
|
}
|
|
|
|
int headLen = 8;
|
|
int len = ( der.length() - 8 ) / 2;
|
|
|
|
String strcertPKX = der.substring(headLen, headLen + 64);
|
|
String strcertPKY = der.substring(headLen + len, headLen + len + 64);
|
|
der = "03420004" + strcertPKX + strcertPKY;
|
|
|
|
return new SimplePublicKey("3059301306072A8648CE3D020106082A811CCF5501822D" + der );
|
|
}
|
|
}
|