unsafe public Int32 SetPrivateKey(sc_entropy_type_e type, string privkey) { byte[] arr = StringToByteArray(privkey); fixed(byte *key = arr) { UInt32 keylen = (UInt32)arr.Length; safecrypto_set_key_coding(SC, type, type); return(safecrypto_private_key_load(SC, key, keylen)); } }
unsafe public string GetPublicKey(sc_entropy_type_e type) { byte * key; UInt32 keylen = 0; safecrypto_set_key_coding(SC, type, type); safecrypto_public_key_encode(SC, &key, &keylen); byte[] pubkey = new byte[keylen]; Marshal.Copy((IntPtr)key, pubkey, 0, (int)keylen); return(ByteArrayToString(pubkey)); }
unsafe public byte[] SignatureTranscode(sc_entropy_type_e From, sc_entropy_type_e To, byte[] Signature, out UInt32 Length) { byte * Sig; UInt32 SigLen; UInt32 VectorLen; fixed(byte *SigPtr = Signature) { Int32 RetCode = safecrypto_signature_transcode(SC, From, To, SigPtr, (UInt32)Signature.Length, &Sig, &SigLen, &VectorLen); if (0 == RetCode) { throw new ArgumentException("Return code failure"); } byte[] SigBuf = new byte[SigLen]; Marshal.Copy((IntPtr)Sig, SigBuf, 0, (int)SigLen); Length = VectorLen; return(SigBuf); } }
unsafe public string GetPrivateKey(sc_entropy_type_e type) { byte * key; UInt32 keylen = 0; safecrypto_set_key_coding(SC, type, type); int RetVal = safecrypto_private_key_encode(SC, &key, &keylen); if (RetVal == 0) { UInt32 Code = safecrypto_err_get_error(SC); Console.WriteLine("Code: {0}", Code); return(Code.ToString()); } else { byte[] privkey = new byte[keylen]; Marshal.Copy((IntPtr)key, privkey, 0, (int)keylen); return(ByteArrayToString(privkey)); } }
public unsafe static extern Int32 safecrypto_signature_transcode(IntPtr sc, sc_entropy_type_e from, sc_entropy_type_e to, byte *sigbuf, UInt32 siglen, byte **sigtrans, UInt32 *sigtranslen, UInt32 *length);
public static extern Int32 safecrypto_set_key_coding(IntPtr sc, sc_entropy_type_e pub, sc_entropy_type_e priv);