อย่าใช้ในการผลิตนี่คือสถานะ POC
ตัวอย่างพื้นฐานมีอยู่ในไดเรกทอรี examples
<?php
declare (strict_types= 1 );
require ' ../vendor/autoload.php ' ;
use Gheb ShamirSecretSharingScheme SodiumHelper ;
use Gheb ShamirSecretSharingScheme ShamirSecretSharingHelper ;
$ secretKey = SodiumHelper:: generateKey (); // this will be stored in shares.
$ nonce = SodiumHelper:: generateNonce (); // this could be part of your app configuration
$ secret = ' Sensitive information ' ;
var_dump ( " secret : $ secret " );
// symmetric key encryption with padded message to hide it's length. This does not matter, it's for show !
$ encryptedMessage = SodiumHelper:: encrypt ( $ secret , $ secretKey , $ nonce );
// This is the best part !
// It splits the secret key into 3 shares. (but it could be more)
// initialisation of modulo value, addressing insecure integer arithmetic.
// this would be part of your app configuration or stored elsewhere.
$ m = " 997 " ; // chose any prime number (here around 1000)
$ points = ShamirSecretSharingHelper:: getShareablePoints ( $ secretKey , $ m , 3 );
var_dump ( $ points );
// there you can store your points at different locations.
// and later get them back to get your secret back
// reconstructing and decrypting
// to reconstruct the secretKey the 3 points are needed along the
$ decryptedSecretKey = ShamirSecretSharingHelper:: reconstructSecret ( $ points , $ m );
$ decryptedSecret = SodiumHelper:: decrypt ( $ encryptedMessage , $ nonce , $ decryptedSecretKey );
var_dump ( " decrypted secret : $ decryptedSecret " ); https://en.wikipedia.org/wiki/homomorphic_secret_sharing
https://en.wikipedia.org/wiki/shamir%27s_secret_sharing
https://wiki.owasp.org/index.php/security_by_design_principles
https://kariera.future-processing.pl/blog/splitting-your-secrets-with-shamirs-secret-sharing-scheme/
https://www.geeeksforgeeks.org/shamirs-secret-sharing-algorithm-cryptography/
https://ericrafaloff.com/shamirs-secret-sharing-scheme/
รูปแบบการแบ่งปันความลับของ Sharmir เสนอความปลอดภัยทางทฤษฎีข้อมูลซึ่งหมายความว่าคณิตศาสตร์ที่เราสำรวจได้รับการพิสูจน์แล้วว่าไม่สามารถแตกหักได้แม้กับผู้โจมตีที่มีพลังคอมพิวเตอร์ไม่ จำกัด อย่างไรก็ตามโครงการยังคงมีปัญหาสองประการ
ตัวอย่างเช่นโครงการของ Shamir ไม่ได้ผลิตหุ้นที่ตรวจสอบได้ซึ่งหมายความว่าบุคคลมีอิสระที่จะส่งหุ้นปลอมและป้องกันความลับที่ถูกต้องจากการสร้างใหม่ ผู้ถือหุ้นที่เป็นปฏิปักษ์ที่มีข้อมูลเพียงพอสามารถสร้างส่วนแบ่งที่แตกต่างกันเพื่อให้ SS ถูกสร้างขึ้นใหม่เป็นมูลค่าของตัวเลือกของพวกเขา ปัญหานี้ได้รับการแก้ไขโดยแผนการแบ่งปันความลับที่ตรวจสอบได้เช่นโครงการของ Feldman
อีกประเด็นหนึ่งคือเนื่องจากความยาวของหุ้นที่กำหนดเท่ากับความยาวของความลับที่เกี่ยวข้องความยาวของความลับจะรั่วไหลได้ง่าย ปัญหานี้เป็นเรื่องเล็กน้อยที่จะแก้ไขโดยเพียงแค่เติมความลับให้กับความยาวคงที่ซึ่งควรทำด้วยโซเดียมตามที่แสดงในตัวอย่าง
ในที่สุดมันเป็นสิ่งสำคัญที่จะต้องทราบว่าความกังวลของเราเกี่ยวกับความปลอดภัยอาจขยายออกไปเพียงแค่โครงการเอง สำหรับแอพพลิเคชั่นการเข้ารหัสในโลกแห่งความเป็นจริงมักจะมีการคุกคามของการโจมตีช่องทางด้านข้างซึ่งผู้โจมตีพยายามแยกข้อมูลที่เป็นประโยชน์จากเวลาแอปพลิเคชันการแคชความผิดและอื่น ๆ หากนี่เป็นข้อกังวลควรพิจารณาอย่างรอบคอบในระหว่างการพัฒนาเช่นการใช้ฟังก์ชั่นเวลาคงที่และการค้นหาการป้องกันไม่ให้หน่วยความจำจากการเพจไปยังดิสก์และสิ่งอื่น ๆ ที่อยู่นอกเหนือขอบเขตของห้องสมุดนี้