예제 #1
0
파일: util.go 프로젝트: vanadium/go.jni
// GoPublicKey converts the provided Java PublicKey into Go PublicKey.
func GoPublicKey(env jutil.Env, jKey jutil.Object) (security.PublicKey, error) {
	der, err := JavaPublicKeyToDER(env, jKey)
	if err != nil {
		return nil, err
	}
	return security.UnmarshalPublicKey(der)
}
예제 #2
0
파일: signer.go 프로젝트: vanadium/go.jni
func (s *signer) PublicKey() security.PublicKey {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	publicKeySign := jutil.ClassSign("java.security.interfaces.ECPublicKey")
	jPublicKey, err := jutil.CallObjectMethod(env, s.jSigner, "publicKey", nil, publicKeySign)
	if err != nil {
		log.Printf("Couldn't get Java public key: %v", err)
		return nil
	}
	// Get the encoded version of the public key.
	encoded, err := jutil.CallByteArrayMethod(env, jPublicKey, "getEncoded", nil)
	if err != nil {
		log.Printf("Couldn't get encoded data for Java public key: %v", err)
		return nil
	}
	key, err := security.UnmarshalPublicKey(encoded)
	if err != nil {
		log.Printf("Couldn't parse Java ECDSA public key: " + err.Error())
		return nil
	}
	return key
}