Beispiel #1
0
func NewOcCredLoadFromFile(filename string) (*OcCred, error) {
	if filename == "" {
		filename = PRIVATE_KEY_FILENAME
	}
	file, err := util.GetAppData(filename)
	if err != nil {
		return nil, fmt.Errorf("error getting app data: %v", err.Error())
	}
	var d big.Int
	fmt.Fscanf(file, "%x\n", &d)
	curve := elliptic.P256()
	x, y := curve.ScalarBaseMult(d.Bytes())
	priv := ecdsa.PrivateKey{
		PublicKey: ecdsa.PublicKey{
			Curve: curve,
			X:     x,
			Y:     y,
		},
		D: &d,
	}

	ocCred := OcCred{
		Priv: &priv,
	}

	return &ocCred, nil
}
Beispiel #2
0
func NewOcCredLoadOrCreate(filename string) (*OcCred, error) {
	if filename == "" {
		filename = PRIVATE_KEY_FILENAME
	}
	file, _ := util.GetAppData(filename)
	if file != nil {
		return NewOcCredLoadFromFile(filename)
	} else {
		ocCred := NewOcCred()
		err := ocCred.StorePrivateKey("")
		if err != nil {
			return nil, err
		}
		return ocCred, nil
	}
}