本文整理汇总了C#中ECPoint类的典型用法代码示例。如果您正苦于以下问题:C# ECPoint类的具体用法?C# ECPoint怎么用?C# ECPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ECPoint类属于命名空间,在下文中一共展示了ECPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecipherKey
public byte[] DecipherKey(BigInteger privateKey, ECPoint tag)
{
var keyPoint = tag.Multiply(privateKey);
var key = SHA256.DoubleHash(keyPoint.EncodePoint(false));
return key;
}
示例2: Parse
/// <summary>
/// Parses an elliptic curve point.
/// </summary>
/// <param name="data">octet data</param>
/// <param name="ec">elliptic curve domain parameters</param>
/// <param name="p">an elliptic curve point object</param>
/// <returns>true if parsing and validation succeeded</returns>
public static bool Parse(byte[] data, EllipticCurve ec, out ECPoint p) {
if (IsZero(data)) {
// point at infinity
p = null;
return false;
}
if (data.Length < 2) {
// invalid length
p = null;
return false;
}
if (data[0] == 0x04) {
ECPoint tmp = ParseUncompressed(data);
if (tmp == null) {
p = null;
return false;
}
if (!ec.ValidatePoint(tmp)) {
p = null;
return false;
}
p = tmp;
p.Validated = true;
return true;
}
// Compressed form of EC point is not supported.
// OpenSSL, which is used by OpenSSH for cryptography, disables
// EC point compression by default due to the patent reason.
p = null;
return false;
}
示例3: MultiplyPositive
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
{
ECCurve curveOrig = p.Curve;
ECCurve curveAdd = ConfigureCurve(curveOrig, additionCoord);
ECCurve curveDouble = ConfigureCurve(curveOrig, doublingCoord);
int[] naf = WNafUtilities.GenerateCompactNaf(k);
ECPoint Ra = curveAdd.Infinity;
ECPoint Td = curveDouble.ImportPoint(p);
int zeroes = 0;
for (int i = 0; i < naf.Length; ++i)
{
int ni = naf[i];
int digit = ni >> 16;
zeroes += ni & 0xFFFF;
Td = Td.TimesPow2(zeroes);
ECPoint Tj = curveAdd.ImportPoint(Td);
if (digit < 0)
{
Tj = Tj.Negate();
}
Ra = Ra.Add(Tj);
zeroes = 1;
}
return curveOrig.ImportPoint(Ra);
}
示例4: GenerateKey
public ECPoint GenerateKey(ECPoint publicKey, out byte[] key, BigInteger? k)
{
for (int i = 0; i < 100; i++)
{
if (k == null)
{
byte[] kBytes = new byte[33];
rngCsp.GetBytes(kBytes);
kBytes[32] = 0;
k = new BigInteger(kBytes);
}
if (k.Value.IsZero || k.Value >= Secp256k1.N) continue;
var tag = Secp256k1.G.Multiply(k.Value);
var keyPoint = publicKey.Multiply(k.Value);
if (keyPoint.IsInfinity || tag.IsInfinity) continue;
key = SHA256.DoubleHash(keyPoint.EncodePoint(false));
return tag;
}
throw new Exception("Unable to generate key");
}
示例5: Multiply
/**
* D.3.2 pg 101
* @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
*/
public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
{
// TODO Probably should try to add this
// BigInteger e = k.Mod(n); // n == order of p
BigInteger e = k;
BigInteger h = e.Multiply(BigInteger.Three);
ECPoint neg = p.Negate();
ECPoint R = p;
for (int i = h.BitLength - 2; i > 0; --i)
{
R = R.Twice();
bool hBit = h.TestBit(i);
bool eBit = e.TestBit(i);
if (hBit != eBit)
{
R = R.Add(hBit ? p : neg);
}
}
return R;
}
示例6: Encrypt
public byte[] Encrypt(ECPoint publicKey, byte[] data)
{
byte[] key;
var tag = ecElGamal.GenerateKey(publicKey, out key);
var tagBytes = tag.EncodePoint(false);
byte[] iv = new byte[16];
rngCsp.GetBytes(iv);
aesEncryption.IV = iv;
aesEncryption.Key = key;
ICryptoTransform crypto = aesEncryption.CreateEncryptor();
byte[] cipherData = crypto.TransformFinalBlock(data, 0, data.Length);
byte[] cipher = new byte[cipherData.Length + 65 + 16];
Buffer.BlockCopy(tagBytes, 0, cipher, 0, 65);
Buffer.BlockCopy(aesEncryption.IV, 0, cipher, 65, 16);
Buffer.BlockCopy(cipherData, 0, cipher, 65 + 16, cipherData.Length);
return cipher;
}
示例7: PublicKey
public PublicKey(ECPoint point)
{
this.IsCompressedPoint = point.IsCompressed;
this.point = point;
this.PublicKeyBytes = point.GetEncoded();
if (validatePoint() == false) throw new ArgumentException("Not a valid public key");
}
示例8: CreateSignatureRedeemScript
public static byte[] CreateSignatureRedeemScript(ECPoint publicKey)
{
using (ScriptBuilder sb = new ScriptBuilder())
{
sb.Push(publicKey.EncodePoint(true));
sb.Add(ScriptOp.OP_CHECKSIG);
return sb.ToArray();
}
}
示例9: Create
public static SignatureContract Create(ECPoint publicKey)
{
return new SignatureContract
{
RedeemScript = CreateSignatureRedeemScript(publicKey),
PublicKeyHash = publicKey.EncodePoint(true).ToScriptHash(),
publicKey = publicKey
};
}
示例10: PointDoubling
public void PointDoubling(
BigInteger x1, BigInteger y1,
BigInteger x2, BigInteger y2)
{
var p = new ECPoint(x1, y1);
var expected = new ECPoint(x2, y2);
Assert.True(expected == 2*p);
}
示例11: Multiply
public virtual ECPoint Multiply(ECPoint p, BigInteger k)
{
int sign = k.SignValue;
if (sign == 0 || p.IsInfinity)
return p.Curve.Infinity;
ECPoint positive = MultiplyPositive(p, k.Abs());
return sign > 0 ? positive : positive.Negate();
}
示例12: ECCurve
private ECCurve(BigInteger Q, BigInteger A, BigInteger B, BigInteger N, byte[] G)
{
this.Q = Q;
this.A = new ECFieldElement(A, this);
this.B = new ECFieldElement(B, this);
this.N = N;
this.Infinity = new ECPoint(null, null, this);
this.G = ECPoint.DecodePoint(G, this);
}
示例13: PointAddition
public void PointAddition(
BigInteger x1, BigInteger y1,
BigInteger x2, BigInteger y2,
BigInteger x3, BigInteger y3)
{
var p1 = new ECPoint(x1, y1);
var p2 = new ECPoint(x2, y2);
var expected = new ECPoint(x3, y3);
Assert.True(expected == p1 + p2);
}
示例14: MultiplyPositive
/**
* Joye's double-add algorithm.
*/
protected override ECPoint MultiplyPositive(ECPoint p, BigInteger k)
{
ECPoint[] R = new ECPoint[]{ p.Curve.Infinity, p };
int n = k.BitLength;
for (int i = 0; i < n; ++i)
{
int b = k.TestBit(i) ? 1 : 0;
int bp = 1 - b;
R[bp] = R[bp].TwicePlus(R[b]);
}
return R[0];
}
示例15: Add
public bool Add(byte[] redeemScript, ECPoint pubkey, byte[] signature)
{
UInt160 scriptHash = redeemScript.ToScriptHash();
for (int i = 0; i < ScriptHashes.Length; i++)
{
if (ScriptHashes[i] == scriptHash)
{
if (signatures[i] == null)
signatures[i] = new MultiSigContext(redeemScript);
return signatures[i].Add(pubkey, signature);
}
}
return false;
}